[pypy-svn] r25840 - in pypy/dist/pypy: rpython/lltypesystem translator/goal

antocuni at codespeak.net antocuni at codespeak.net
Sat Apr 15 10:22:45 CEST 2006


Author: antocuni
Date: Sat Apr 15 10:22:17 2006
New Revision: 25840

Added:
   pypy/dist/pypy/translator/goal/targetrlisttest.py   (contents, props changed)
Modified:
   pypy/dist/pypy/rpython/lltypesystem/rlist.py
Log:
Experimental "ll_getelement" interface in rlist.py.

ll_getelement is intended to do a fast element lookup, with no index
checking. There is a commented "ll_listindex" function that uses that
interfaces, too.

The new translator/goal/targetrslisttest.py does some performance test
for the ll_listindex function.



Modified: pypy/dist/pypy/rpython/lltypesystem/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rlist.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rlist.py	Sat Apr 15 10:22:17 2006
@@ -204,6 +204,7 @@
                                           "ll_items": ll_items,
                                           "list_builder": self.list_builder,
                                           "ITEM": ITEM,
+                                          "ll_getelement": ll_getelement # XXX: experimental
                                       })
                              )
 
@@ -278,6 +279,7 @@
                                      "ll_items": ll_fixed_items,
                                      "list_builder": self.list_builder,
                                      "ITEM": ITEM,
+                                     "ll_getelement": ll_getelement # XXX: experimental
                                 })
 
             self.LIST.become(ITEMARRAY)
@@ -819,6 +821,24 @@
         j += 1
     raise ValueError # can't say 'list.index(x): x not in list'
 
+# XXX experimental: this version uses the getelement interface
+##def ll_listindex(lst, obj, eqfn):
+##    lng = lst.ll_length()
+##    j = 0
+##    while j < lng:
+##        if eqfn is None:
+##            if lst.ll_getelement(j) == obj:
+##                return j
+##        else:
+##            if eqfn(lst.ll_getelement(j), obj):
+##                return j
+##        j += 1
+##    raise ValueError # can't say 'list.index(x): x not in list'
+
+# XXX experimental
+def ll_getelement(lst, index):
+    return lst.ll_items()[index]
+
 TEMP = GcArray(Ptr(rstr.STR))
 
 def ll_inplace_mul(l, factor):

Added: pypy/dist/pypy/translator/goal/targetrlisttest.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/goal/targetrlisttest.py	Sat Apr 15 10:22:17 2006
@@ -0,0 +1,23 @@
+from pypy.rpython.objectmodel import r_dict
+import os, sys
+import operator
+import time
+
+# __________  Entry point  __________
+
+N_ITEMS = 100000000
+
+def entry_point(argv):
+    lst = range(N_ITEMS)
+    lst[0] = 1
+    start = time.time()
+    lst.index(N_ITEMS-1)
+    end = time.time()
+    os.write(1, 'Time elapsed: %s\n' % (end-start))
+    return 0
+
+# _____ Define and setup target ___
+
+def target(*args):
+    return entry_point, None
+



More information about the Pypy-commit mailing list