[Jython-checkins] jython: Add strided slice operation to the benchmmark for unicode operations.

jeff.allen jython-checkins at python.org
Wed Sep 17 00:55:25 CEST 2014


http://hg.python.org/jython/rev/a5d1fd17e143
changeset:   7382:a5d1fd17e143
user:        Jeff Allen <ja.py at farowl.co.uk>
date:        Sun Sep 07 22:56:03 2014 +0100
summary:
  Add strided slice operation to the benchmmark for unicode operations.

files:
  tests/python/unicode_index_times.py |  53 ++++++++++++++--
  1 files changed, 45 insertions(+), 8 deletions(-)


diff --git a/tests/python/unicode_index_times.py b/tests/python/unicode_index_times.py
--- a/tests/python/unicode_index_times.py
+++ b/tests/python/unicode_index_times.py
@@ -179,11 +179,47 @@
                 starts = n - m + 1
                 for i in range(starts):
                     dummy = t[i:i+m]
+                    #print(i, i+m, step, dummy)
                 opcount += starts
                 m *= 5
 
         return opcount
 
+    def repeat_slice_step(self, mincount):
+        ''' Extract a slice at each feasible position and length,
+            and using different sizes for the step,
+            repeating enough times to do mincount operations, and
+            return the actual number of operations.
+        '''
+        n = self.size
+        t = self.text
+        opcount = 0
+        dummy = None
+        steps = [3, -1, 10]
+
+        while opcount < mincount:
+            for step in steps:
+                if step > 0:
+                    m = 1
+                    while m <= n:
+                        starts = n - m + 1
+                        for i in range(starts):
+                            dummy = t[i:i+m:step]
+                            #print(i, i+m, step, dummy)
+                        opcount += starts
+                        m *= 5
+                else:
+                    m = 1
+                    while m <= n:
+                        starts = n - m + 1
+                        for i in range(starts):
+                            dummy = t[i+m:i:step]
+                            #print(i+m, i, step, dummy)
+                        opcount += starts
+                        m *= 5
+                    
+        return opcount
+
     def repeat_find_char(self, mincount):
         ''' Do an incremental find of each code point, repeating
             enough times to do mincount finds, and return the actual
@@ -313,8 +349,8 @@
         ("long bmp", UnicodeActions(LONG, (lambda ran, i : False))),
         ("long 1%", UnicodeActions(LONG, evenly(0.01))),
         ("long 10%", UnicodeActions(LONG, evenly(0.1))),
-        ("long 10% low", UnicodeActions(LONG, evenly_before(LONG/4, 0.4))),
-        ("long 10% high", UnicodeActions(LONG, evenly_from(LONG-(LONG/4), 0.4))),
+        ("long 10% L", UnicodeActions(LONG, evenly_before(LONG/4, 0.4))),
+        ("long 10% H", UnicodeActions(LONG, evenly_from(LONG-(LONG/4), 0.4))),
         ("long 50%", UnicodeActions(LONG, evenly(0.5))),
         ("huge bmp", UnicodeActions(HUGE, (lambda ran, i : False))),
         ("huge 10%", UnicodeActions(HUGE, evenly(0.1))),
@@ -323,16 +359,17 @@
     ops = [
         ("[i]", "repeat_getitem"),
         ("[i:i+n]", "repeat_slice"),
+        ("[i:i+n:k]", "repeat_slice_step"),
         ("find(c)", "repeat_find_char"),
-        ("find(str)", "repeat_find_str"),
+        ("find(s)", "repeat_find_str"),
         ("rfind(c)", "repeat_rfind_char"),
-        ("rfind(str)", "repeat_rfind_str"),
+        ("rfind(s)", "repeat_rfind_str"),
     ]
 
 
-    print("{:15s}{:>6s}".format("time (us)", "len"), end='')
+    print("{:12s}{:>6s}".format("time (us)", "len"), end='')
     for title, _ in ops:
-        print("{:>12s}".format(title), end='')
+        print("{:>10s}".format(title), end='')
     print()
 
     mintime = dict()
@@ -355,10 +392,10 @@
 
     # Cycle through the cases again to print them.
     for name, material in setups:
-        print("{:15s}{:6d}".format(name, material.size), end='')
+        print("{:12s}{:6d}".format(name, material.size), end='')
         for _, opname in ops:
             t = mintime[(name, opname)]
-            print("{:12.3f}".format(t), end='')
+            print("{:10.2f}".format(t), end='')
         print()
 
     print("y =", trashcan)

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list