Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90382

Re: Calling a function is faster than not calling it?

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 <skip.montanaro@gmail.com>
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> <fNP3x.641427$3i4.583649@fx29.am4> <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 <skip.montanaro@gmail.com>
To BartC <bc@freeuk.com>
Cc Python <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.365.1431353538.12865.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Mon, May 11, 2015 at 4:50 AM, BartC <bc@freeuk.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Calling a function is faster than not calling it? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-10 19:58 +1000
  Re: Calling a function is faster than not calling it? Christian Gollwitzer <auriocus@gmx.de> - 2015-05-10 12:34 +0200
    Re: Calling a function is faster than not calling it? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-11 01:04 +1000
  Re: Calling a function is faster than not calling it? Peter Otten <__peter__@web.de> - 2015-05-10 12:43 +0200
    Re: Calling a function is faster than not calling it? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-11 00:49 +1000
      Re: Calling a function is faster than not calling it? Peter Otten <__peter__@web.de> - 2015-05-10 18:14 +0200
      Re: Calling a function is faster than not calling it? Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-10 10:25 -0600
  Re: Calling a function is faster than not calling it? Terry Reedy <tjreedy@udel.edu> - 2015-05-10 12:37 -0400
  Re: Calling a function is faster than not calling it? BartC <bc@freeuk.com> - 2015-05-10 22:08 +0100
    Re: Calling a function is faster than not calling it? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-11 13:58 +1000
      Re: Calling a function is faster than not calling it? BartC <bc@freeuk.com> - 2015-05-11 10:50 +0100
        Re: Calling a function is faster than not calling it? Skip Montanaro <skip.montanaro@gmail.com> - 2015-05-11 09:12 -0500
          Re: Calling a function is faster than not calling it? BartC <bc@freeuk.com> - 2015-05-11 16:01 +0100
            Re: Calling a function is faster than not calling it? Skip Montanaro <skip.montanaro@gmail.com> - 2015-05-11 10:13 -0500
      Re: Calling a function is faster than not calling it? Tony the Tiger <tony@tiger.invalid> - 2015-05-15 01:35 +0000
  Re: Calling a function is faster than not calling it? Stefan Behnel <stefan_ml@behnel.de> - 2015-05-11 08:11 +0200
  Re: Calling a function is faster than not calling it? Piet van Oostrum <piet@vanoostrum.org> - 2015-06-22 23:49 +0200

csiph-web