[Python-checkins] r46087 - sandbox/trunk/stringbench/stringbench.py

fredrik.lundh python-checkins at python.org
Tue May 23 10:58:27 CEST 2006


Author: fredrik.lundh
Date: Tue May 23 10:58:26 2006
New Revision: 46087

Modified:
   sandbox/trunk/stringbench/stringbench.py
Log:
whitespace normalization
added a summary lines



Modified: sandbox/trunk/stringbench/stringbench.py
==============================================================================
--- sandbox/trunk/stringbench/stringbench.py	(original)
+++ sandbox/trunk/stringbench/stringbench.py	Tue May 23 10:58:26 2006
@@ -85,7 +85,7 @@
     search = pat.search
     for x in _RANGE_100:
         search(s1)
-        
+
 
 #### same tests as 'in' but use 'find'
 
@@ -122,7 +122,7 @@
     for x in _RANGE_1000:
         s1_find(s2)
 
- at bench('"BC" in ("AB"*1000+"C")', group="late match, two characters")
+ at bench('("AB"*1000+"C").find("BC")', group="late match, two characters")
 def find_test_slow_match_two_characters(STR):
     s1 = STR("AB" * 1000+"C")
     s2 = STR("BC")
@@ -143,7 +143,7 @@
 #### Now with index.
 # Skip the ones which fail because the
 
-        
+
 @bench('("A"*1000).index("A")', group="early match, single character")
 def index_test_quick_match_single_character(STR):
     s1 = STR("A" * 1000)
@@ -204,7 +204,7 @@
     s = STR("ABCDE")
     for x in _RANGE_1000:
         s * 1000
-        
+
 # + for concat
 
 @bench('"Andrew"+"Dalke"', "concat two strings")
@@ -323,14 +323,14 @@
     s_split = s.split
     for x in _RANGE_1000:
         s_split("\n")
-        
+
 @bench('"this\\nis\\na\\ntest\\n".rsplit("\\n")', "split newlines")
 def newlines_rsplit(STR):
     s = STR("this\nis\na\ntest\n")
     s_rsplit = s.rsplit
     for x in _RANGE_1000:
         s_rsplit("\n")
-        
+
 @bench('"this\\nis\\na\\ntest\\n".splitlines()', "split newlines")
 def newlines_splitlines(STR):
     s = STR("this\nis\na\ntest\n")
@@ -339,7 +339,7 @@
         s_splitlines()
 
 ## split text with 2000 newlines
-    
+
 def _make_2000_lines():
     import random
     r = random.Random(100)
@@ -360,7 +360,7 @@
     if STR is str:
         return _text_with_2000_lines
     raise AssertionError
-        
+
 
 @bench('"...text...".split("\\n")', "split 2000 newlines")
 def newlines_split_2000(STR):
@@ -368,14 +368,14 @@
     s_split = s.split
     for x in _RANGE_100:
         s_split("\n")
-        
+
 @bench('"...text...".rsplit("\\n")', "split 2000 newlines")
 def newlines_rsplit_2000(STR):
     s = _get_2000_lines(STR)
     s_rsplit = s.rsplit
     for x in _RANGE_100:
         s_rsplit("\n")
-        
+
 @bench('"...text...".splitlines()', "split 2000 newlines")
 def newlines_splitlines_2000(STR):
     s = _get_2000_lines(STR)
@@ -414,21 +414,21 @@
     s_split = s.split
     for x in _RANGE_1000:
         s_split("\t")
-        
+
 @bench('GFF3_example.split("\\t", 8)', "tab split")
 def tab_split_limit(STR):
     s = STR(GFF3_example)
     s_split = s.split
     for x in _RANGE_1000:
         s_split("\t", 8)
-        
+
 @bench('GFF3_example.rsplit("\\t")', "tab split")
 def tab_rsplit_no_limit(STR):
     s = STR(GFF3_example)
     s_rsplit = s.rsplit
     for x in _RANGE_1000:
         s_rsplit("\t")
-        
+
 @bench('GFF3_example.rsplit("\\t", 8)', "tab split")
 def tab_rsplit_limit(STR):
     s = STR(GFF3_example)
@@ -595,7 +595,7 @@
         s[:-1] if (s[-1] == NL) else s
 
 
-        
+
 # strip
 # lstrip
 # rstrip
@@ -627,7 +627,7 @@
 
 def main():
     test_names = sys.argv[1:]
-    
+
     bench_functions = []
     for (k,v) in globals().items():
         if hasattr(v, "is_bench"):
@@ -644,6 +644,8 @@
     print "string\tunicode"
     print "(in ms)\t(in ms)\t%\tcomment"
 
+    str_total = uni_total = 0
+
     for title, group in itertools.groupby(bench_functions,
                                       operator.itemgetter(0)):
         print "="*10, title
@@ -656,7 +658,14 @@
                 print "%.2f\t%.2f\t%.1f\t%s" % (
                     1000*str_time, 1000*uni_time, 100.*str_time/uni_time,
                     v.comment)
+                str_total += str_time
+                uni_total += uni_time
+
+    print "%.2f\t%.2f\t%.1f\t%s" % (
+        1000*str_total, 1000*uni_total, 100.*str_total/uni_total,
+        "TOTAL")
+
 
 if __name__ == "__main__":
     main()
-    
+


More information about the Python-checkins mailing list