Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'heavily': 0.04; 'interpreter': 0.05; 'expressions': 0.07; 'string': 0.09; 'subset': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "wouldn't": 0.14; '(without': 0.16; 'overlaps': 0.16; 'slow,': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'compilation': 0.24; 'skip': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'object.': 0.31; 'quite': 0.32; 'up.': 0.33; 'call.': 0.33; 'guess': 0.33; 'could': 0.34; 'except': 0.35; 'form.': 0.35; 'received:google.com': 0.35; 'doubt': 0.36; 'subject:?': 0.36; 'expect': 0.39; 'most': 0.60; 'simple': 0.61; 'places': 0.64; 'different': 0.65; 'direct': 0.67; 'containing': 0.69; 'evaluate': 0.72; 'attention': 0.75; '2015': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=GQsQHzaOEOB3sBIPaIsRZdmA0y1qZbTW8jXulZ3lZN8=; b=HWrAu13nDl25FDNsJx1dpCvKrj3atcJ6QJAz37m39cLRzQyUp+hi+LbCE4S59d9JDX +ZZ81DG9IRg/XXmyarJzFmBj1+lWhN6kKv2W3R3qWyvDKKuyx/Ka9EUFXooovTn1nsYb VQo4C7xZcMqyFuddho24GcDo2zjtuhJhAqLSnHcX4XsFAWGBjK+6QB1zHoWXabzg51Rr 1H4NsASJvSvbDdhJrMuWOvHOS0FAtz6R19uHZkTUlNJJiLThkDlgYSWlv2P9j7H8JfL5 qgZOSWcWjK3Fk0+lw5r7otT4xJ5rKSRyx80DnbAINmEB6E8gEDJ6kzZeKNBDI7w7va1x ga+Q== MIME-Version: 1.0 X-Received: by 10.182.186.4 with SMTP id fg4mr8045299obc.7.1431353530610; Mon, 11 May 2015 07:12:10 -0700 (PDT) In-Reply-To: <8Y_3x.668959$LI3.568865@fx24.am4> References: <554f2bb6$0$13011$c3e8da3$5496439d@news.astraweb.com> <555028d8$0$12997$c3e8da3$5496439d@news.astraweb.com> <8Y_3x.668959$LI3.568865@fx24.am4> Date: Mon, 11 May 2015 09:12:10 -0500 Subject: Re: Calling a function is faster than not calling it? From: Skip Montanaro To: BartC Cc: Python Content-Type: multipart/alternative; boundary=089e013cbeacbd794d0515cef638 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431353538 news.xs4all.nl 2941 [2001:888:2000:d::a6]:58757 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90382 --089e013cbeacbd794d0515cef638 Content-Type: text/plain; charset=UTF-8 On Mon, May 11, 2015 at 4:50 AM, BartC wrote: > You just seem surprised that using eval() to do this is slower than a > direct call. Well, it is surprising. Most uses of eval() are to evaluate Python expressions in string form. That I expect to be quite slow, given the parsing+byte compilation overhead. I wouldn't expect eval()ing a code object to be all that different than calling the function containing the code object. My guess (without looking in ceval.c) is that the code path through the VM has been tweaked heavily over the years to try and speed it up. Except for places where that path overlaps with the path for eval(code_object), I doubt any attention has been paid to speeding up eval. I could certainly be way off-base here. Perhaps the path taken through the interpreter for eval(code_object) is more-or-less a subset of the path taken for a simple function call. Skip --089e013cbeacbd794d0515cef638 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

= On Mon, May 11, 2015 at 4:50 AM, BartC <bc@freeuk.com> wrote:
You just seem surprised that using eval() t= o do this is slower than a direct call.

Well, it is s= urprising. Most uses of eval() are to evaluate Python expressions in string= form. That I expect to be quite slow, given the parsing+byte compilation o= verhead. I wouldn't expect eval()ing a code object to be all that diffe= rent than calling the function containing the code object.

My guess (without loo= king in ceval.c) is that the code path through the VM has been tweaked heav= ily over the years to try and speed it up. Except for places where that pat= h overlaps with the path for eval(code_object), I doubt any attention has b= een paid to speeding up eval. I could certainly be way off-base here. Perha= ps the path taken through the interpreter for eval(code_object) is more-or-= less a subset of the path taken for a simple function call.

Skip

--089e013cbeacbd794d0515cef638--