ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-dev
python-dev
Re: [Python-Dev] Draft proposal: Implicit self in Python 3.0
by Ralf W. Grosse-Kunstleve other posts by this author
Jan 8 2006 7:36AM messages near this date
Re: [Python-Dev] Draft proposal: Implicit self in Python 3.0 | Re: [Python-Dev] Draft proposal: Implicit self in Python 3.0
--- Fredrik Lundh <fredrik@[...].com>  wrote:

>  Ralf W. Grosse-Kunstleve wrote:
>  
>  > ***Please*** make Python more selfish. Note that this is also an obvious
>  avenue
>  > for significant performance increases. If self is implicit you don't have
>  to do
>  > the dictionary lookup for "self" all the time as is the case now.
>  
>  what dictionary lookup ?

IIUC, "self" is first looked up in the local dictionary.

Please try the code below to see the performance impact. As an alternative to a
copy/paste exercise try this:

wget http://cci.lbl.gov/~rwgk/python/self_lookup.py
python self_lookup.py

The output with Python 2.4.1/Fedora3/Opteron is:

loop_function: 13.10
   loop_class: 17.11

Cheers,
        Ralf


import time

def loop_function(x, n):
  result = 0
  for i in xrange(n):
    result += x
  return result

class loop_class:

  def __init__(self, x, n):
    self.x = x
    self.n = n

  def __call__(self):
    result = 0
    for i in xrange(self.n):
      result += self.x
    return result

def run(x=3.1415, n=10**8):
  t0 = time.time()
  loop_function(x=x, n=n)
  print "loop_function: %.2f" % (time.time() - t0)
  t0 = time.time()
  loop_class(x=x, n=n)()
  print "   loop_class: %.2f" % (time.time() - t0)

if (__name__ == "__main__"):
  run()



		
__________________________________________ 
Yahoo! DSL Â? Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 

_______________________________________________
Python-Dev mailing list
Python-Dev@[...].org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.c
om
Thread:
Alexander Kozlovsky
Ralf W. Grosse-Kunstleve
Ian Bicking
Thomas Wouters
Tim Peters
Brett Cannon
Fredrik Lundh
Ralf W. Grosse-Kunstleve
Samuele Pedroni
Fredrik Lundh
Ralf W. Grosse-Kunstleve
Thomas Wouters
Ralf W. Grosse-Kunstleve
Phillip J. Eby
Thomas Wouters
Fredrik Lundh
Armin Rigo
Guido van Rossum
Ralf W. Grosse-Kunstleve
"Martin v. Löwis"
"Martin v. Löwis"
Kay Schluehr
Guido van Rossum
Thomas Wouters
Phillip J. Eby
"Martin v. Löwis"
Thomas Wouters
"Martin v. Löwis"
Thomas Wouters
Tim Peters
Ian Bicking
Thomas Wouters
Ian Bicking
Samuele Pedroni
Kay Schluehr
Alexander Kozlovsky
Jim Jewett
Fabien Schwob
Kay Schluehr
Nick Coghlan
Ian Bicking
"Martin v. Löwis"

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved