annotate Tools/stringbench/stringbench.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 6b28bfff9204
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
76179
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
2 # Various microbenchmarks comparing unicode and byte string performance
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
3 # Please keep this file both 2.x and 3.x compatible!
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
4
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
5 import timeit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
6 import itertools
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
7 import operator
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
8 import re
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
9 import sys
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
10 import datetime
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
11 import optparse
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
12
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
13 VERSION = '2.0'
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
14
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
15 def p(*args):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
16 sys.stdout.write(' '.join(str(s) for s in args) + '\n')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
17
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
18 if sys.version_info >= (3,):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
19 BYTES = bytes_from_str = lambda x: x.encode('ascii')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
20 UNICODE = unicode_from_str = lambda x: x
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
21 else:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
22 BYTES = bytes_from_str = lambda x: x
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
23 UNICODE = unicode_from_str = lambda x: x.decode('ascii')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
24
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
25 class UnsupportedType(TypeError):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
26 pass
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
27
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
28
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
29 p('stringbench v%s' % VERSION)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
30 p(sys.version)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
31 p(datetime.datetime.now())
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
32
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
33 REPEAT = 1
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
34 REPEAT = 3
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
35 #REPEAT = 7
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
36
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
37 if __name__ != "__main__":
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
38 raise SystemExit("Must run as main program")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
39
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
40 parser = optparse.OptionParser()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
41 parser.add_option("-R", "--skip-re", dest="skip_re",
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
42 action="store_true",
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
43 help="skip regular expression tests")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
44 parser.add_option("-8", "--8-bit", dest="bytes_only",
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
45 action="store_true",
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
46 help="only do 8-bit string benchmarks")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
47 parser.add_option("-u", "--unicode", dest="unicode_only",
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
48 action="store_true",
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
49 help="only do Unicode string benchmarks")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
50
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
51
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
52 _RANGE_1000 = list(range(1000))
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
53 _RANGE_100 = list(range(100))
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
54 _RANGE_10 = list(range(10))
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
55
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
56 dups = {}
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
57 def bench(s, group, repeat_count):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
58 def blah(f):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
59 if f.__name__ in dups:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
60 raise AssertionError("Multiple functions with same name: %r" %
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
61 (f.__name__,))
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
62 dups[f.__name__] = 1
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
63 f.comment = s
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
64 f.is_bench = True
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
65 f.group = group
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
66 f.repeat_count = repeat_count
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
67 return f
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
68 return blah
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
69
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
70 def uses_re(f):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
71 f.uses_re = True
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
72
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
73 ####### 'in' comparisons
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
74
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
75 @bench('"A" in "A"*1000', "early match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
76 def in_test_quick_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
77 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
78 s2 = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
79 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
80 s2 in s1
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
81
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
82 @bench('"B" in "A"*1000', "no match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
83 def in_test_no_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
84 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
85 s2 = STR("B")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
86 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
87 s2 in s1
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
88
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
89
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
90 @bench('"AB" in "AB"*1000', "early match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
91 def in_test_quick_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
92 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
93 s2 = STR("AB")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
94 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
95 s2 in s1
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
96
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
97 @bench('"BC" in "AB"*1000', "no match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
98 def in_test_no_match_two_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
99 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
100 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
101 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
102 s2 in s1
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
103
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
104 @bench('"BC" in ("AB"*300+"C")', "late match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
105 def in_test_slow_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
106 s1 = STR("AB" * 300+"C")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
107 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
108 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
109 s2 in s1
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
110
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
111 @bench('s="ABC"*33; (s+"E") in ((s+"D")*300+s+"E")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
112 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
113 def in_test_slow_match_100_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
114 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
115 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
116 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
117 s1 = (m+d)*300 + m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
118 s2 = m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
119 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
120 s2 in s1
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
121
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
122 # Try with regex
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
123 @uses_re
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
124 @bench('s="ABC"*33; re.compile(s+"D").search((s+"D")*300+s+"E")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
125 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
126 def re_test_slow_match_100_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
127 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
128 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
129 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
130 s1 = (m+d)*300 + m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
131 s2 = m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
132 pat = re.compile(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
133 search = pat.search
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
134 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
135 search(s1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
136
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
137
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
138 #### same tests as 'in' but use 'find'
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
139
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
140 @bench('("A"*1000).find("A")', "early match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
141 def find_test_quick_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
142 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
143 s2 = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
144 s1_find = s1.find
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
145 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
146 s1_find(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
147
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
148 @bench('("A"*1000).find("B")', "no match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
149 def find_test_no_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
150 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
151 s2 = STR("B")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
152 s1_find = s1.find
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
153 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
154 s1_find(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
155
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
156
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
157 @bench('("AB"*1000).find("AB")', "early match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
158 def find_test_quick_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
159 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
160 s2 = STR("AB")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
161 s1_find = s1.find
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
162 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
163 s1_find(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
164
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
165 @bench('("AB"*1000).find("BC")', "no match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
166 def find_test_no_match_two_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
167 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
168 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
169 s1_find = s1.find
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
170 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
171 s1_find(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
172
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
173 @bench('("AB"*1000).find("CA")', "no match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
174 def find_test_no_match_two_character_bis(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
175 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
176 s2 = STR("CA")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
177 s1_find = s1.find
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
178 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
179 s1_find(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
180
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
181 @bench('("AB"*300+"C").find("BC")', "late match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
182 def find_test_slow_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
183 s1 = STR("AB" * 300+"C")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
184 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
185 s1_find = s1.find
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
186 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
187 s1_find(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
188
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
189 @bench('("AB"*300+"CA").find("CA")', "late match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
190 def find_test_slow_match_two_characters_bis(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
191 s1 = STR("AB" * 300+"CA")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
192 s2 = STR("CA")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
193 s1_find = s1.find
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
194 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
195 s1_find(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
196
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
197 @bench('s="ABC"*33; ((s+"D")*500+s+"E").find(s+"E")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
198 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
199 def find_test_slow_match_100_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
200 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
201 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
202 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
203 s1 = (m+d)*500 + m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
204 s2 = m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
205 s1_find = s1.find
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
206 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
207 s1_find(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
208
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
209 @bench('s="ABC"*33; ((s+"D")*500+"E"+s).find("E"+s)',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
210 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
211 def find_test_slow_match_100_characters_bis(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
212 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
213 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
214 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
215 s1 = (m+d)*500 + e+m
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
216 s2 = e+m
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
217 s1_find = s1.find
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
218 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
219 s1_find(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
220
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
221
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
222 #### Same tests for 'rfind'
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
223
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
224 @bench('("A"*1000).rfind("A")', "early match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
225 def rfind_test_quick_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
226 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
227 s2 = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
228 s1_rfind = s1.rfind
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
229 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
230 s1_rfind(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
231
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
232 @bench('("A"*1000).rfind("B")', "no match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
233 def rfind_test_no_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
234 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
235 s2 = STR("B")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
236 s1_rfind = s1.rfind
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
237 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
238 s1_rfind(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
239
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
240
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
241 @bench('("AB"*1000).rfind("AB")', "early match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
242 def rfind_test_quick_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
243 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
244 s2 = STR("AB")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
245 s1_rfind = s1.rfind
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
246 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
247 s1_rfind(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
248
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
249 @bench('("AB"*1000).rfind("BC")', "no match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
250 def rfind_test_no_match_two_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
251 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
252 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
253 s1_rfind = s1.rfind
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
254 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
255 s1_rfind(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
256
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
257 @bench('("AB"*1000).rfind("CA")', "no match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
258 def rfind_test_no_match_two_character_bis(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
259 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
260 s2 = STR("CA")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
261 s1_rfind = s1.rfind
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
262 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
263 s1_rfind(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
264
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
265 @bench('("C"+"AB"*300).rfind("CA")', "late match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
266 def rfind_test_slow_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
267 s1 = STR("C" + "AB" * 300)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
268 s2 = STR("CA")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
269 s1_rfind = s1.rfind
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
270 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
271 s1_rfind(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
272
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
273 @bench('("BC"+"AB"*300).rfind("BC")', "late match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
274 def rfind_test_slow_match_two_characters_bis(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
275 s1 = STR("BC" + "AB" * 300)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
276 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
277 s1_rfind = s1.rfind
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
278 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
279 s1_rfind(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
280
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
281 @bench('s="ABC"*33; ("E"+s+("D"+s)*500).rfind("E"+s)',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
282 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
283 def rfind_test_slow_match_100_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
284 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
285 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
286 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
287 s1 = e+m + (d+m)*500
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
288 s2 = e+m
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
289 s1_rfind = s1.rfind
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
290 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
291 s1_rfind(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
292
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
293 @bench('s="ABC"*33; (s+"E"+("D"+s)*500).rfind(s+"E")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
294 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
295 def rfind_test_slow_match_100_characters_bis(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
296 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
297 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
298 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
299 s1 = m+e + (d+m)*500
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
300 s2 = m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
301 s1_rfind = s1.rfind
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
302 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
303 s1_rfind(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
304
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
305
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
306 #### Now with index.
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
307 # Skip the ones which fail because that would include exception overhead.
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
308
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
309 @bench('("A"*1000).index("A")', "early match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
310 def index_test_quick_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
311 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
312 s2 = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
313 s1_index = s1.index
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
314 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
315 s1_index(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
316
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
317 @bench('("AB"*1000).index("AB")', "early match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
318 def index_test_quick_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
319 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
320 s2 = STR("AB")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
321 s1_index = s1.index
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
322 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
323 s1_index(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
324
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
325 @bench('("AB"*300+"C").index("BC")', "late match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
326 def index_test_slow_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
327 s1 = STR("AB" * 300+"C")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
328 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
329 s1_index = s1.index
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
330 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
331 s1_index(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
332
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
333 @bench('s="ABC"*33; ((s+"D")*500+s+"E").index(s+"E")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
334 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
335 def index_test_slow_match_100_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
336 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
337 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
338 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
339 s1 = (m+d)*500 + m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
340 s2 = m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
341 s1_index = s1.index
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
342 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
343 s1_index(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
344
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
345
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
346 #### Same for rindex
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
347
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
348 @bench('("A"*1000).rindex("A")', "early match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
349 def rindex_test_quick_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
350 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
351 s2 = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
352 s1_rindex = s1.rindex
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
353 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
354 s1_rindex(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
355
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
356 @bench('("AB"*1000).rindex("AB")', "early match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
357 def rindex_test_quick_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
358 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
359 s2 = STR("AB")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
360 s1_rindex = s1.rindex
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
361 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
362 s1_rindex(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
363
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
364 @bench('("C"+"AB"*300).rindex("CA")', "late match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
365 def rindex_test_slow_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
366 s1 = STR("C" + "AB" * 300)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
367 s2 = STR("CA")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
368 s1_rindex = s1.rindex
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
369 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
370 s1_rindex(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
371
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
372 @bench('s="ABC"*33; ("E"+s+("D"+s)*500).rindex("E"+s)',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
373 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
374 def rindex_test_slow_match_100_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
375 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
376 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
377 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
378 s1 = e + m + (d+m)*500
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
379 s2 = e + m
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
380 s1_rindex = s1.rindex
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
381 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
382 s1_rindex(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
383
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
384
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
385 #### Same for partition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
386
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
387 @bench('("A"*1000).partition("A")', "early match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
388 def partition_test_quick_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
389 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
390 s2 = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
391 s1_partition = s1.partition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
392 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
393 s1_partition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
394
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
395 @bench('("A"*1000).partition("B")', "no match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
396 def partition_test_no_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
397 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
398 s2 = STR("B")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
399 s1_partition = s1.partition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
400 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
401 s1_partition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
402
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
403
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
404 @bench('("AB"*1000).partition("AB")', "early match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
405 def partition_test_quick_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
406 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
407 s2 = STR("AB")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
408 s1_partition = s1.partition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
409 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
410 s1_partition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
411
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
412 @bench('("AB"*1000).partition("BC")', "no match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
413 def partition_test_no_match_two_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
414 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
415 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
416 s1_partition = s1.partition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
417 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
418 s1_partition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
419
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
420 @bench('("AB"*300+"C").partition("BC")', "late match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
421 def partition_test_slow_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
422 s1 = STR("AB" * 300+"C")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
423 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
424 s1_partition = s1.partition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
425 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
426 s1_partition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
427
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
428 @bench('s="ABC"*33; ((s+"D")*500+s+"E").partition(s+"E")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
429 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
430 def partition_test_slow_match_100_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
431 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
432 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
433 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
434 s1 = (m+d)*500 + m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
435 s2 = m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
436 s1_partition = s1.partition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
437 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
438 s1_partition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
439
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
440
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
441 #### Same for rpartition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
442
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
443 @bench('("A"*1000).rpartition("A")', "early match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
444 def rpartition_test_quick_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
445 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
446 s2 = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
447 s1_rpartition = s1.rpartition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
448 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
449 s1_rpartition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
450
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
451 @bench('("A"*1000).rpartition("B")', "no match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
452 def rpartition_test_no_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
453 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
454 s2 = STR("B")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
455 s1_rpartition = s1.rpartition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
456 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
457 s1_rpartition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
458
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
459
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
460 @bench('("AB"*1000).rpartition("AB")', "early match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
461 def rpartition_test_quick_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
462 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
463 s2 = STR("AB")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
464 s1_rpartition = s1.rpartition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
465 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
466 s1_rpartition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
467
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
468 @bench('("AB"*1000).rpartition("BC")', "no match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
469 def rpartition_test_no_match_two_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
470 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
471 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
472 s1_rpartition = s1.rpartition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
473 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
474 s1_rpartition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
475
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
476 @bench('("C"+"AB"*300).rpartition("CA")', "late match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
477 def rpartition_test_slow_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
478 s1 = STR("C" + "AB" * 300)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
479 s2 = STR("CA")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
480 s1_rpartition = s1.rpartition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
481 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
482 s1_rpartition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
483
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
484 @bench('s="ABC"*33; ("E"+s+("D"+s)*500).rpartition("E"+s)',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
485 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
486 def rpartition_test_slow_match_100_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
487 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
488 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
489 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
490 s1 = e + m + (d+m)*500
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
491 s2 = e + m
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
492 s1_rpartition = s1.rpartition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
493 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
494 s1_rpartition(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
495
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
496
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
497 #### Same for split(s, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
498
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
499 @bench('("A"*1000).split("A", 1)', "early match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
500 def split_test_quick_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
501 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
502 s2 = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
503 s1_split = s1.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
504 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
505 s1_split(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
506
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
507 @bench('("A"*1000).split("B", 1)', "no match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
508 def split_test_no_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
509 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
510 s2 = STR("B")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
511 s1_split = s1.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
512 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
513 s1_split(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
514
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
515
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
516 @bench('("AB"*1000).split("AB", 1)', "early match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
517 def split_test_quick_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
518 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
519 s2 = STR("AB")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
520 s1_split = s1.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
521 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
522 s1_split(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
523
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
524 @bench('("AB"*1000).split("BC", 1)', "no match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
525 def split_test_no_match_two_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
526 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
527 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
528 s1_split = s1.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
529 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
530 s1_split(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
531
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
532 @bench('("AB"*300+"C").split("BC", 1)', "late match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
533 def split_test_slow_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
534 s1 = STR("AB" * 300+"C")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
535 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
536 s1_split = s1.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
537 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
538 s1_split(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
539
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
540 @bench('s="ABC"*33; ((s+"D")*500+s+"E").split(s+"E", 1)',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
541 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
542 def split_test_slow_match_100_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
543 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
544 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
545 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
546 s1 = (m+d)*500 + m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
547 s2 = m+e
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
548 s1_split = s1.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
549 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
550 s1_split(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
551
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
552
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
553 #### Same for rsplit(s, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
554
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
555 @bench('("A"*1000).rsplit("A", 1)', "early match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
556 def rsplit_test_quick_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
557 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
558 s2 = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
559 s1_rsplit = s1.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
560 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
561 s1_rsplit(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
562
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
563 @bench('("A"*1000).rsplit("B", 1)', "no match, single character", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
564 def rsplit_test_no_match_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
565 s1 = STR("A" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
566 s2 = STR("B")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
567 s1_rsplit = s1.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
568 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
569 s1_rsplit(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
570
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
571
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
572 @bench('("AB"*1000).rsplit("AB", 1)', "early match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
573 def rsplit_test_quick_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
574 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
575 s2 = STR("AB")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
576 s1_rsplit = s1.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
577 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
578 s1_rsplit(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
579
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
580 @bench('("AB"*1000).rsplit("BC", 1)', "no match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
581 def rsplit_test_no_match_two_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
582 s1 = STR("AB" * 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
583 s2 = STR("BC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
584 s1_rsplit = s1.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
585 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
586 s1_rsplit(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
587
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
588 @bench('("C"+"AB"*300).rsplit("CA", 1)', "late match, two characters", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
589 def rsplit_test_slow_match_two_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
590 s1 = STR("C" + "AB" * 300)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
591 s2 = STR("CA")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
592 s1_rsplit = s1.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
593 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
594 s1_rsplit(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
595
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
596 @bench('s="ABC"*33; ("E"+s+("D"+s)*500).rsplit("E"+s, 1)',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
597 "late match, 100 characters", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
598 def rsplit_test_slow_match_100_characters(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
599 m = STR("ABC"*33)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
600 d = STR("D")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
601 e = STR("E")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
602 s1 = e + m + (d+m)*500
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
603 s2 = e + m
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
604 s1_rsplit = s1.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
605 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
606 s1_rsplit(s2, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
607
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
608
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
609 #### Benchmark the operator-based methods
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
610
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
611 @bench('"A"*10', "repeat 1 character 10 times", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
612 def repeat_single_10_times(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
613 s = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
614 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
615 s * 10
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
616
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
617 @bench('"A"*1000', "repeat 1 character 1000 times", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
618 def repeat_single_1000_times(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
619 s = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
620 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
621 s * 1000
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
622
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
623 @bench('"ABCDE"*10', "repeat 5 characters 10 times", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
624 def repeat_5_10_times(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
625 s = STR("ABCDE")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
626 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
627 s * 10
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
628
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
629 @bench('"ABCDE"*1000', "repeat 5 characters 1000 times", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
630 def repeat_5_1000_times(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
631 s = STR("ABCDE")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
632 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
633 s * 1000
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
634
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
635 # + for concat
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
636
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
637 @bench('"Andrew"+"Dalke"', "concat two strings", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
638 def concat_two_strings(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
639 s1 = STR("Andrew")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
640 s2 = STR("Dalke")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
641 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
642 s1+s2
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
643
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
644 @bench('s1+s2+s3+s4+...+s20', "concat 20 strings of words length 4 to 15",
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
645 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
646 def concat_many_strings(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
647 s1=STR('TIXSGYNREDCVBHJ')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
648 s2=STR('PUMTLXBZVDO')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
649 s3=STR('FVZNJ')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
650 s4=STR('OGDXUW')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
651 s5=STR('WEIMRNCOYVGHKB')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
652 s6=STR('FCQTNMXPUZH')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
653 s7=STR('TICZJYRLBNVUEAK')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
654 s8=STR('REYB')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
655 s9=STR('PWUOQ')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
656 s10=STR('EQHCMKBS')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
657 s11=STR('AEVDFOH')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
658 s12=STR('IFHVD')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
659 s13=STR('JGTCNLXWOHQ')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
660 s14=STR('ITSKEPYLROZAWXF')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
661 s15=STR('THEK')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
662 s16=STR('GHPZFBUYCKMNJIT')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
663 s17=STR('JMUZ')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
664 s18=STR('WLZQMTB')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
665 s19=STR('KPADCBW')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
666 s20=STR('TNJHZQAGBU')
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
667 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
668 (s1 + s2+ s3+ s4+ s5+ s6+ s7+ s8+ s9+s10+
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
669 s11+s12+s13+s14+s15+s16+s17+s18+s19+s20)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
670
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
671
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
672 #### Benchmark join
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
673
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
674 def get_bytes_yielding_seq(STR, arg):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
675 if STR is BYTES and sys.version_info >= (3,):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
676 raise UnsupportedType
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
677 return STR(arg)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
678
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
679 @bench('"A".join("")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
680 "join empty string, with 1 character sep", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
681 def join_empty_single(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
682 sep = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
683 s2 = get_bytes_yielding_seq(STR, "")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
684 sep_join = sep.join
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
685 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
686 sep_join(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
687
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
688 @bench('"ABCDE".join("")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
689 "join empty string, with 5 character sep", 100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
690 def join_empty_5(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
691 sep = STR("ABCDE")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
692 s2 = get_bytes_yielding_seq(STR, "")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
693 sep_join = sep.join
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
694 for x in _RANGE_100:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
695 sep_join(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
696
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
697 @bench('"A".join("ABC..Z")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
698 "join string with 26 characters, with 1 character sep", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
699 def join_alphabet_single(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
700 sep = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
701 s2 = get_bytes_yielding_seq(STR, "ABCDEFGHIJKLMnOPQRSTUVWXYZ")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
702 sep_join = sep.join
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
703 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
704 sep_join(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
705
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
706 @bench('"ABCDE".join("ABC..Z")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
707 "join string with 26 characters, with 5 character sep", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
708 def join_alphabet_5(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
709 sep = STR("ABCDE")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
710 s2 = get_bytes_yielding_seq(STR, "ABCDEFGHIJKLMnOPQRSTUVWXYZ")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
711 sep_join = sep.join
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
712 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
713 sep_join(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
714
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
715 @bench('"A".join(list("ABC..Z"))',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
716 "join list of 26 characters, with 1 character sep", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
717 def join_alphabet_list_single(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
718 sep = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
719 s2 = [STR(x) for x in "ABCDEFGHIJKLMnOPQRSTUVWXYZ"]
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
720 sep_join = sep.join
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
721 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
722 sep_join(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
723
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
724 @bench('"ABCDE".join(list("ABC..Z"))',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
725 "join list of 26 characters, with 5 character sep", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
726 def join_alphabet_list_five(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
727 sep = STR("ABCDE")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
728 s2 = [STR(x) for x in "ABCDEFGHIJKLMnOPQRSTUVWXYZ"]
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
729 sep_join = sep.join
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
730 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
731 sep_join(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
732
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
733 @bench('"A".join(["Bob"]*100))',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
734 "join list of 100 words, with 1 character sep", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
735 def join_100_words_single(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
736 sep = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
737 s2 = [STR("Bob")]*100
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
738 sep_join = sep.join
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
739 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
740 sep_join(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
741
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
742 @bench('"ABCDE".join(["Bob"]*100))',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
743 "join list of 100 words, with 5 character sep", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
744 def join_100_words_5(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
745 sep = STR("ABCDE")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
746 s2 = [STR("Bob")]*100
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
747 sep_join = sep.join
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
748 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
749 sep_join(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
750
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
751 #### split tests
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
752
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
753 @bench('("Here are some words. "*2).split()', "split whitespace (small)", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
754 def whitespace_split(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
755 s = STR("Here are some words. "*2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
756 s_split = s.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
757 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
758 s_split()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
759
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
760 @bench('("Here are some words. "*2).rsplit()', "split whitespace (small)", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
761 def whitespace_rsplit(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
762 s = STR("Here are some words. "*2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
763 s_rsplit = s.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
764 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
765 s_rsplit()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
766
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
767 @bench('("Here are some words. "*2).split(None, 1)',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
768 "split 1 whitespace", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
769 def whitespace_split_1(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
770 s = STR("Here are some words. "*2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
771 s_split = s.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
772 N = None
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
773 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
774 s_split(N, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
775
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
776 @bench('("Here are some words. "*2).rsplit(None, 1)',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
777 "split 1 whitespace", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
778 def whitespace_rsplit_1(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
779 s = STR("Here are some words. "*2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
780 s_rsplit = s.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
781 N = None
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
782 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
783 s_rsplit(N, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
784
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
785 @bench('("Here are some words. "*2).partition(" ")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
786 "split 1 whitespace", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
787 def whitespace_partition(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
788 sep = STR(" ")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
789 s = STR("Here are some words. "*2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
790 s_partition = s.partition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
791 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
792 s_partition(sep)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
793
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
794 @bench('("Here are some words. "*2).rpartition(" ")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
795 "split 1 whitespace", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
796 def whitespace_rpartition(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
797 sep = STR(" ")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
798 s = STR("Here are some words. "*2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
799 s_rpartition = s.rpartition
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
800 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
801 s_rpartition(sep)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
802
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
803 human_text = """\
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
804 Python is a dynamic object-oriented programming language that can be
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
805 used for many kinds of software development. It offers strong support
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
806 for integration with other languages and tools, comes with extensive
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
807 standard libraries, and can be learned in a few days. Many Python
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
808 programmers report substantial productivity gains and feel the language
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
809 encourages the development of higher quality, more maintainable code.
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
810
79479
d853354e1470 #16135: Removal of OS/2 support (Remove OS2 and OS/2 references)
Jesus Cea <jcea@jcea.es>
parents: 76180
diff changeset
811 Python runs on Windows, Linux/Unix, Mac OS X, Amiga, Palm
76179
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
812 Handhelds, and Nokia mobile phones. Python has also been ported to the
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
813 Java and .NET virtual machines.
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
814
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
815 Python is distributed under an OSI-approved open source license that
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
816 makes it free to use, even for commercial products.
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
817 """*25
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
818 human_text_bytes = bytes_from_str(human_text)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
819 human_text_unicode = unicode_from_str(human_text)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
820 def _get_human_text(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
821 if STR is UNICODE:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
822 return human_text_unicode
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
823 if STR is BYTES:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
824 return human_text_bytes
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
825 raise AssertionError
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
826
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
827 @bench('human_text.split()', "split whitespace (huge)", 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
828 def whitespace_split_huge(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
829 s = _get_human_text(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
830 s_split = s.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
831 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
832 s_split()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
833
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
834 @bench('human_text.rsplit()', "split whitespace (huge)", 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
835 def whitespace_rsplit_huge(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
836 s = _get_human_text(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
837 s_rsplit = s.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
838 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
839 s_rsplit()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
840
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
841
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
842
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
843 @bench('"this\\nis\\na\\ntest\\n".split("\\n")', "split newlines", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
844 def newlines_split(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
845 s = STR("this\nis\na\ntest\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
846 s_split = s.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
847 nl = STR("\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
848 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
849 s_split(nl)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
850
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
851
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
852 @bench('"this\\nis\\na\\ntest\\n".rsplit("\\n")', "split newlines", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
853 def newlines_rsplit(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
854 s = STR("this\nis\na\ntest\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
855 s_rsplit = s.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
856 nl = STR("\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
857 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
858 s_rsplit(nl)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
859
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
860 @bench('"this\\nis\\na\\ntest\\n".splitlines()', "split newlines", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
861 def newlines_splitlines(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
862 s = STR("this\nis\na\ntest\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
863 s_splitlines = s.splitlines
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
864 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
865 s_splitlines()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
866
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
867 ## split text with 2000 newlines
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
868
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
869 def _make_2000_lines():
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
870 import random
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
871 r = random.Random(100)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
872 chars = list(map(chr, range(32, 128)))
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
873 i = 0
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
874 while i < len(chars):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
875 chars[i] = " "
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
876 i += r.randrange(9)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
877 s = "".join(chars)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
878 s = s*4
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
879 words = []
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
880 for i in range(2000):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
881 start = r.randrange(96)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
882 n = r.randint(5, 65)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
883 words.append(s[start:start+n])
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
884 return "\n".join(words)+"\n"
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
885
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
886 _text_with_2000_lines = _make_2000_lines()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
887 _text_with_2000_lines_bytes = bytes_from_str(_text_with_2000_lines)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
888 _text_with_2000_lines_unicode = unicode_from_str(_text_with_2000_lines)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
889 def _get_2000_lines(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
890 if STR is UNICODE:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
891 return _text_with_2000_lines_unicode
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
892 if STR is BYTES:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
893 return _text_with_2000_lines_bytes
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
894 raise AssertionError
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
895
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
896
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
897 @bench('"...text...".split("\\n")', "split 2000 newlines", 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
898 def newlines_split_2000(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
899 s = _get_2000_lines(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
900 s_split = s.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
901 nl = STR("\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
902 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
903 s_split(nl)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
904
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
905 @bench('"...text...".rsplit("\\n")', "split 2000 newlines", 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
906 def newlines_rsplit_2000(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
907 s = _get_2000_lines(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
908 s_rsplit = s.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
909 nl = STR("\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
910 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
911 s_rsplit(nl)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
912
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
913 @bench('"...text...".splitlines()', "split 2000 newlines", 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
914 def newlines_splitlines_2000(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
915 s = _get_2000_lines(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
916 s_splitlines = s.splitlines
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
917 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
918 s_splitlines()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
919
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
920
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
921 ## split text on "--" characters
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
922 @bench(
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
923 '"this--is--a--test--of--the--emergency--broadcast--system".split("--")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
924 "split on multicharacter separator (small)", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
925 def split_multichar_sep_small(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
926 s = STR("this--is--a--test--of--the--emergency--broadcast--system")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
927 s_split = s.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
928 pat = STR("--")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
929 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
930 s_split(pat)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
931 @bench(
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
932 '"this--is--a--test--of--the--emergency--broadcast--system".rsplit("--")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
933 "split on multicharacter separator (small)", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
934 def rsplit_multichar_sep_small(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
935 s = STR("this--is--a--test--of--the--emergency--broadcast--system")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
936 s_rsplit = s.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
937 pat = STR("--")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
938 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
939 s_rsplit(pat)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
940
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
941 ## split dna text on "ACTAT" characters
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
942 @bench('dna.split("ACTAT")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
943 "split on multicharacter separator (dna)", 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
944 def split_multichar_sep_dna(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
945 s = _get_dna(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
946 s_split = s.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
947 pat = STR("ACTAT")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
948 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
949 s_split(pat)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
950
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
951 @bench('dna.rsplit("ACTAT")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
952 "split on multicharacter separator (dna)", 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
953 def rsplit_multichar_sep_dna(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
954 s = _get_dna(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
955 s_rsplit = s.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
956 pat = STR("ACTAT")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
957 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
958 s_rsplit(pat)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
959
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
960
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
961
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
962 ## split with limits
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
963
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
964 GFF3_example = "\t".join([
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
965 "I", "Genomic_canonical", "region", "357208", "396183", ".", "+", ".",
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
966 "ID=Sequence:R119;note=Clone R119%3B Genbank AF063007;Name=R119"])
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
967
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
968 @bench('GFF3_example.split("\\t")', "tab split", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
969 def tab_split_no_limit(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
970 sep = STR("\t")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
971 s = STR(GFF3_example)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
972 s_split = s.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
973 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
974 s_split(sep)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
975
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
976 @bench('GFF3_example.split("\\t", 8)', "tab split", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
977 def tab_split_limit(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
978 sep = STR("\t")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
979 s = STR(GFF3_example)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
980 s_split = s.split
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
981 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
982 s_split(sep, 8)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
983
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
984 @bench('GFF3_example.rsplit("\\t")', "tab split", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
985 def tab_rsplit_no_limit(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
986 sep = STR("\t")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
987 s = STR(GFF3_example)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
988 s_rsplit = s.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
989 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
990 s_rsplit(sep)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
991
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
992 @bench('GFF3_example.rsplit("\\t", 8)', "tab split", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
993 def tab_rsplit_limit(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
994 sep = STR("\t")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
995 s = STR(GFF3_example)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
996 s_rsplit = s.rsplit
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
997 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
998 s_rsplit(sep, 8)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
999
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1000 #### Count characters
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1001
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1002 @bench('...text.with.2000.newlines.count("\\n")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1003 "count newlines", 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1004 def count_newlines(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1005 s = _get_2000_lines(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1006 s_count = s.count
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1007 nl = STR("\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1008 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1009 s_count(nl)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1010
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1011 # Orchid sequences concatenated, from Biopython
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1012 _dna = """
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1013 CGTAACAAGGTTTCCGTAGGTGAACCTGCGGAAGGATCATTGTTGAGATCACATAATAATTGATCGGGTT
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1014 AATCTGGAGGATCTGTTTACTTTGGTCACCCATGAGCATTTGCTGTTGAAGTGACCTAGAATTGCCATCG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1015 AGCCTCCTTGGGAGCTTTCTTGTTGGCGAGATCTAAACCCTTGCCCGGCGCAGTTTTGCTCCAAGTCGTT
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1016 TGACACATAATTGGTGAAGGGGGTGGCATCCTTCCCTGACCCTCCCCCAACTATTTTTTTAACAACTCTC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1017 AGCAACGGAGACTCAGTCTTCGGCAAATGCGATAAATGGTGTGAATTGCAGAATCCCGTGCACCATCGAG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1018 TCTTTGAACGCAAGTTGCGCCCGAGGCCATCAGGCCAAGGGCACGCCTGCCTGGGCATTGCGAGTCATAT
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1019 CTCTCCCTTAACGAGGCTGTCCATACATACTGTTCAGCCGGTGCGGATGTGAGTTTGGCCCCTTGTTCTT
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1020 TGGTACGGGGGGTCTAAGAGCTGCATGGGCTTTTGATGGTCCTAAATACGGCAAGAGGTGGACGAACTAT
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1021 GCTACAACAAAATTGTTGTGCAGAGGCCCCGGGTTGTCGTATTAGATGGGCCACCGTAATCTGAAGACCC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1022 TTTTGAACCCCATTGGAGGCCCATCAACCCATGATCAGTTGATGGCCATTTGGTTGCGACCCCAGGTCAG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1023 GTGAGCAACAGCTGTCGTAACAAGGTTTCCGTAGGGTGAACTGCGGAAGGATCATTGTTGAGATCACATA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1024 ATAATTGATCGAGTTAATCTGGAGGATCTGTTTACTTGGGTCACCCATGGGCATTTGCTGTTGAAGTGAC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1025 CTAGATTTGCCATCGAGCCTCCTTGGGAGCATCCTTGTTGGCGATATCTAAACCCTCAATTTTTCCCCCA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1026 ATCAAATTACACAAAATTGGTGGAGGGGGTGGCATTCTTCCCTTACCCTCCCCCAAATATTTTTTTAACA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1027 ACTCTCAGCAACGGATATCTCAGCTCTTGCATCGATGAAGAACCCACCGAAATGCGATAAATGGTGTGAA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1028 TTGCAGAATCCCGTGAACCATCGAGTCTTTGAACGCAAGTTGCGCCCGAGGCCATCAGGCCAAGGGCACG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1029 CCTGCCTGGGCATTGCGAGTCATATCTCTCCCTTAACGAGGCTGTCCATACATACTGTTCAGCCGGTGCG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1030 GATGTGAGTTTGGCCCCTTGTTCTTTGGTACGGGGGGTCTAAGAGATGCATGGGCTTTTGATGGTCCTAA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1031 ATACGGCAAGAGGTGGACGAACTATGCTACAACAAAATTGTTGTGCAAAGGCCCCGGGTTGTCGTATAAG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1032 ATGGGCCACCGATATCTGAAGACCCTTTTGGACCCCATTGGAGCCCATCAACCCATGTCAGTTGATGGCC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1033 ATTCGTAACAAGGTTTCCGTAGGTGAACCTGCGGAAGGATCATTGTTGAGATCACATAATAATTGATCGA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1034 GTTAATCTGGAGGATCTGTTTACTTGGGTCACCCATGGGCATTTGCTGTTGAAGTGACCTAGATTTGCCA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1035 TCGAGCCTCCTTGGGAGCTTTCTTGTTGGCGATATCTAAACCCTTGCCCGGCAGAGTTTTGGGAATCCCG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1036 TGAACCATCGAGTCTTTGAACGCAAGTTGCGCCCGAGGCCATCAGGCCAAGGGCACGCCTGCCTGGGCAT
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1037 TGCGAGTCATATCTCTCCCTTAACGAGGCTGTCCATACACACCTGTTCAGCCGGTGCGGATGTGAGTTTG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1038 GCCCCTTGTTCTTTGGTACGGGGGGTCTAAGAGCTGCATGGGCTTTTGATGGTCCTAAATACGGCAAGAG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1039 GTGGACGAACTATGCTACAACAAAATTGTTGTGCAAAGGCCCCGGGTTGTCGTATTAGATGGGCCACCAT
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1040 AATCTGAAGACCCTTTTGAACCCCATTGGAGGCCCATCAACCCATGATCAGTTGATGGCCATTTGGTTGC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1041 GACCCAGTCAGGTGAGGGTAGGTGAACCTGCGGAAGGATCATTGTTGAGATCACATAATAATTGATCGAG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1042 TTAATCTGGAGGATCTGTTTACTTTGGTCACCCATGGGCATTTGCTGTTGAAGTGACCTAGATTTGCCAT
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1043 CGAGCCTCCTTGGGAGCTTTCTTGTTGGCGAGATCTAAACCCTTGCCCGGCGGAGTTTGGCGCCAAGTCA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1044 TATGACACATAATTGGTGAAGGGGGTGGCATCCTGCCCTGACCCTCCCCAAATTATTTTTTTAACAACTC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1045 TCAGCAACGGATATCTCGGCTCTTGCATCGATGAAGAACGCAGCGAAATGCGATAAATGGTGTGAATTGC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1046 AGAATCCCGTGAACCATCGAGTCTTTGGAACGCAAGTTGCGCCCGAGGCCATCAGGCCAAGGGCACGCCT
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1047 GCCTGGGCATTGGGAATCATATCTCTCCCCTAACGAGGCTATCCAAACATACTGTTCATCCGGTGCGGAT
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1048 GTGAGTTTGGCCCCTTGTTCTTTGGTACCGGGGGTCTAAGAGCTGCATGGGCATTTGATGGTCCTCAAAA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1049 CGGCAAGAGGTGGACGAACTATGCCACAACAAAATTGTTGTCCCAAGGCCCCGGGTTGTCGTATTAGATG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1050 GGCCACCGTAACCTGAAGACCCTTTTGAACCCCATTGGAGGCCCATCAACCCATGATCAGTTGATGACCA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1051 TTTGTTGCGACCCCAGTCAGCTGAGCAACCCGCTGAGTGGAAGGTCATTGCCGATATCACATAATAATTG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1052 ATCGAGTTAATCTGGAGGATCTGTTTACTTGGTCACCCATGAGCATTTGCTGTTGAAGTGACCTAGATTT
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1053 GCCATCGAGCCTCCTTGGGAGTTTTCTTGTTGGCGAGATCTAAACCCTTGCCCGGCGGAGTTGTGCGCCA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1054 AGTCATATGACACATAATTGGTGAAGGGGGTGGCATCCTGCCCTGACCCTCCCCAAATTATTTTTTTAAC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1055 AACTCTCAGCAACGGATATCTCGGCTCTTGCATCGATGAAGAACGCAGCGAAATGCGATAAATGGTGTGA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1056 ATTGCAGAATCCCGTGAACCATCGAGTCTTTGAACGCAAGTTGCGCCCGAGGCCATCAGGCCAAGGGCAC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1057 GCCTGCCTGGGCATTGCGAGTCATATCTCTCCCTTAACGAGGCTGTCCATACATACTGTTCATCCGGTGC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1058 GGATGTGAGTTTGGCCCCTTGTTCTTTGGTACGGGGGGTCTAAGAGCTGCATGGGCATTTGATGGTCCTC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1059 AAAACGGCAAGAGGTGGACGAACTATGCTACAACCAAATTGTTGTCCCAAGGCCCCGGGTTGTCGTATTA
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1060 GATGGGCCACCGTAACCTGAAGACCCTTTTGAACCCCATTGGAGGCCCATCAACCCATGATCAGTTGATG
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1061 ACCATGTGTTGCGACCCCAGTCAGCTGAGCAACGCGCTGAGCGTAACAAGGTTTCCGTAGGTGGACCTCC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1062 GGGAGGATCATTGTTGAGATCACATAATAATTGATCGAGGTAATCTGGAGGATCTGCATATTTTGGTCAC
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1063 """
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1064 _dna = "".join(_dna.splitlines())
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1065 _dna = _dna * 25
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1066 _dna_bytes = bytes_from_str(_dna)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1067 _dna_unicode = unicode_from_str(_dna)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1068
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1069 def _get_dna(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1070 if STR is UNICODE:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1071 return _dna_unicode
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1072 if STR is BYTES:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1073 return _dna_bytes
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1074 raise AssertionError
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1075
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1076 @bench('dna.count("AACT")', "count AACT substrings in DNA example", 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1077 def count_aact(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1078 seq = _get_dna(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1079 seq_count = seq.count
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1080 needle = STR("AACT")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1081 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1082 seq_count(needle)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1083
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1084 ##### startswith and endswith
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1085
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1086 @bench('"Andrew".startswith("A")', 'startswith single character', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1087 def startswith_single(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1088 s1 = STR("Andrew")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1089 s2 = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1090 s1_startswith = s1.startswith
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1091 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1092 s1_startswith(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1093
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1094 @bench('"Andrew".startswith("Andrew")', 'startswith multiple characters',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1095 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1096 def startswith_multiple(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1097 s1 = STR("Andrew")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1098 s2 = STR("Andrew")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1099 s1_startswith = s1.startswith
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1100 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1101 s1_startswith(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1102
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1103 @bench('"Andrew".startswith("Anders")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1104 'startswith multiple characters - not!', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1105 def startswith_multiple_not(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1106 s1 = STR("Andrew")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1107 s2 = STR("Anders")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1108 s1_startswith = s1.startswith
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1109 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1110 s1_startswith(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1111
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1112
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1113 # endswith
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1114
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1115 @bench('"Andrew".endswith("w")', 'endswith single character', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1116 def endswith_single(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1117 s1 = STR("Andrew")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1118 s2 = STR("w")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1119 s1_endswith = s1.endswith
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1120 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1121 s1_endswith(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1122
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1123 @bench('"Andrew".endswith("Andrew")', 'endswith multiple characters', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1124 def endswith_multiple(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1125 s1 = STR("Andrew")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1126 s2 = STR("Andrew")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1127 s1_endswith = s1.endswith
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1128 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1129 s1_endswith(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1130
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1131 @bench('"Andrew".endswith("Anders")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1132 'endswith multiple characters - not!', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1133 def endswith_multiple_not(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1134 s1 = STR("Andrew")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1135 s2 = STR("Anders")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1136 s1_endswith = s1.endswith
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1137 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1138 s1_endswith(s2)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1139
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1140 #### Strip
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1141
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1142 @bench('"Hello!\\n".strip()', 'strip terminal newline', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1143 def terminal_newline_strip_right(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1144 s = STR("Hello!\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1145 s_strip = s.strip
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1146 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1147 s_strip()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1148
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1149 @bench('"Hello!\\n".rstrip()', 'strip terminal newline', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1150 def terminal_newline_rstrip(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1151 s = STR("Hello!\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1152 s_rstrip = s.rstrip
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1153 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1154 s_rstrip()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1155
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1156 @bench('"\\nHello!".strip()', 'strip terminal newline', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1157 def terminal_newline_strip_left(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1158 s = STR("\nHello!")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1159 s_strip = s.strip
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1160 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1161 s_strip()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1162
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1163 @bench('"\\nHello!\\n".strip()', 'strip terminal newline', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1164 def terminal_newline_strip_both(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1165 s = STR("\nHello!\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1166 s_strip = s.strip
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1167 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1168 s_strip()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1169
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1170 @bench('"\\nHello!".rstrip()', 'strip terminal newline', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1171 def terminal_newline_lstrip(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1172 s = STR("\nHello!")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1173 s_lstrip = s.lstrip
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1174 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1175 s_lstrip()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1176
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1177 @bench('s="Hello!\\n"; s[:-1] if s[-1]=="\\n" else s',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1178 'strip terminal newline', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1179 def terminal_newline_if_else(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1180 s = STR("Hello!\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1181 NL = STR("\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1182 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1183 s[:-1] if (s[-1] == NL) else s
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1184
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1185
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1186 # Strip multiple spaces or tabs
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1187
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1188 @bench('"Hello\\t \\t".strip()', 'strip terminal spaces and tabs', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1189 def terminal_space_strip(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1190 s = STR("Hello\t \t!")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1191 s_strip = s.strip
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1192 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1193 s_strip()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1194
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1195 @bench('"Hello\\t \\t".rstrip()', 'strip terminal spaces and tabs', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1196 def terminal_space_rstrip(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1197 s = STR("Hello!\t \t")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1198 s_rstrip = s.rstrip
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1199 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1200 s_rstrip()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1201
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1202 @bench('"\\t \\tHello".rstrip()', 'strip terminal spaces and tabs', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1203 def terminal_space_lstrip(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1204 s = STR("\t \tHello!")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1205 s_lstrip = s.lstrip
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1206 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1207 s_lstrip()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1208
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1209
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1210 #### replace
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1211 @bench('"This is a test".replace(" ", "\\t")', 'replace single character',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1212 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1213 def replace_single_character(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1214 s = STR("This is a test!")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1215 from_str = STR(" ")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1216 to_str = STR("\t")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1217 s_replace = s.replace
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1218 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1219 s_replace(from_str, to_str)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1220
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1221 @uses_re
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1222 @bench('re.sub(" ", "\\t", "This is a test"', 'replace single character',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1223 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1224 def replace_single_character_re(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1225 s = STR("This is a test!")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1226 pat = re.compile(STR(" "))
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1227 to_str = STR("\t")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1228 pat_sub = pat.sub
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1229 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1230 pat_sub(to_str, s)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1231
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1232 @bench('"...text.with.2000.lines...replace("\\n", " ")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1233 'replace single character, big string', 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1234 def replace_single_character_big(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1235 s = _get_2000_lines(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1236 from_str = STR("\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1237 to_str = STR(" ")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1238 s_replace = s.replace
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1239 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1240 s_replace(from_str, to_str)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1241
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1242 @uses_re
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1243 @bench('re.sub("\\n", " ", "...text.with.2000.lines...")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1244 'replace single character, big string', 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1245 def replace_single_character_big_re(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1246 s = _get_2000_lines(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1247 pat = re.compile(STR("\n"))
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1248 to_str = STR(" ")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1249 pat_sub = pat.sub
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1250 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1251 pat_sub(to_str, s)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1252
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1253
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1254 @bench('dna.replace("ATC", "ATT")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1255 'replace multiple characters, dna', 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1256 def replace_multiple_characters_dna(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1257 seq = _get_dna(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1258 from_str = STR("ATC")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1259 to_str = STR("ATT")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1260 seq_replace = seq.replace
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1261 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1262 seq_replace(from_str, to_str)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1263
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1264 # This increases the character count
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1265 @bench('"...text.with.2000.newlines...replace("\\n", "\\r\\n")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1266 'replace and expand multiple characters, big string', 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1267 def replace_multiple_character_big(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1268 s = _get_2000_lines(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1269 from_str = STR("\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1270 to_str = STR("\r\n")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1271 s_replace = s.replace
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1272 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1273 s_replace(from_str, to_str)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1274
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1275
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1276 # This decreases the character count
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1277 @bench('"When shall we three meet again?".replace("ee", "")',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1278 'replace/remove multiple characters', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1279 def replace_multiple_character_remove(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1280 s = STR("When shall we three meet again?")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1281 from_str = STR("ee")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1282 to_str = STR("")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1283 s_replace = s.replace
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1284 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1285 s_replace(from_str, to_str)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1286
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1287
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1288 big_s = "A" + ("Z"*128*1024)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1289 big_s_bytes = bytes_from_str(big_s)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1290 big_s_unicode = unicode_from_str(big_s)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1291 def _get_big_s(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1292 if STR is UNICODE: return big_s_unicode
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1293 if STR is BYTES: return big_s_bytes
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1294 raise AssertionError
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1295
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1296 # The older replace implementation counted all matches in
85406
c57d99a8fc42 #18803: fix more typos. Patch by Févry Thibault.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 76180
diff changeset
1297 # the string even when it only needed to make one replacement.
76179
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1298 @bench('("A" + ("Z"*128*1024)).replace("A", "BB", 1)',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1299 'quick replace single character match', 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1300 def quick_replace_single_match(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1301 s = _get_big_s(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1302 from_str = STR("A")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1303 to_str = STR("BB")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1304 s_replace = s.replace
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1305 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1306 s_replace(from_str, to_str, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1307
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1308 @bench('("A" + ("Z"*128*1024)).replace("AZZ", "BBZZ", 1)',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1309 'quick replace multiple character match', 10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1310 def quick_replace_multiple_match(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1311 s = _get_big_s(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1312 from_str = STR("AZZ")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1313 to_str = STR("BBZZ")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1314 s_replace = s.replace
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1315 for x in _RANGE_10:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1316 s_replace(from_str, to_str, 1)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1317
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1318
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1319 ####
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1320
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1321 # CCP does a lot of this, for internationalisation of ingame messages.
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1322 _format = "The %(thing)s is %(place)s the %(location)s."
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1323 _format_dict = { "thing":"THING", "place":"PLACE", "location":"LOCATION", }
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1324 _format_bytes = bytes_from_str(_format)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1325 _format_unicode = unicode_from_str(_format)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1326 _format_dict_bytes = dict((bytes_from_str(k), bytes_from_str(v)) for (k,v) in _format_dict.items())
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1327 _format_dict_unicode = dict((unicode_from_str(k), unicode_from_str(v)) for (k,v) in _format_dict.items())
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1328
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1329 def _get_format(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1330 if STR is UNICODE:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1331 return _format_unicode
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1332 if STR is BYTES:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1333 if sys.version_info >= (3,):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1334 raise UnsupportedType
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1335 return _format_bytes
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1336 raise AssertionError
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1337
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1338 def _get_format_dict(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1339 if STR is UNICODE:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1340 return _format_dict_unicode
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1341 if STR is BYTES:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1342 if sys.version_info >= (3,):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1343 raise UnsupportedType
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1344 return _format_dict_bytes
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1345 raise AssertionError
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1346
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1347 # Formatting.
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1348 @bench('"The %(k1)s is %(k2)s the %(k3)s."%{"k1":"x","k2":"y","k3":"z",}',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1349 'formatting a string type with a dict', 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1350 def format_with_dict(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1351 s = _get_format(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1352 d = _get_format_dict(STR)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1353 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1354 s % d
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1355
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1356
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1357 #### Upper- and lower- case conversion
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1358
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1359 @bench('("Where in the world is Carmen San Deigo?"*10).lower()',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1360 "case conversion -- rare", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1361 def lower_conversion_rare(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1362 s = STR("Where in the world is Carmen San Deigo?"*10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1363 s_lower = s.lower
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1364 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1365 s_lower()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1366
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1367 @bench('("WHERE IN THE WORLD IS CARMEN SAN DEIGO?"*10).lower()',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1368 "case conversion -- dense", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1369 def lower_conversion_dense(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1370 s = STR("WHERE IN THE WORLD IS CARMEN SAN DEIGO?"*10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1371 s_lower = s.lower
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1372 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1373 s_lower()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1374
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1375
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1376 @bench('("wHERE IN THE WORLD IS cARMEN sAN dEIGO?"*10).upper()',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1377 "case conversion -- rare", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1378 def upper_conversion_rare(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1379 s = STR("Where in the world is Carmen San Deigo?"*10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1380 s_upper = s.upper
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1381 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1382 s_upper()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1383
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1384 @bench('("where in the world is carmen san deigo?"*10).upper()',
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1385 "case conversion -- dense", 1000)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1386 def upper_conversion_dense(STR):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1387 s = STR("where in the world is carmen san deigo?"*10)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1388 s_upper = s.upper
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1389 for x in _RANGE_1000:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1390 s_upper()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1391
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1392
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1393 # end of benchmarks
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1394
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1395 #################
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1396
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1397 class BenchTimer(timeit.Timer):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1398 def best(self, repeat=1):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1399 for i in range(1, 10):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1400 number = 10**i
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1401 x = self.timeit(number)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1402 if x > 0.02:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1403 break
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1404 times = [x]
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1405 for i in range(1, repeat):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1406 times.append(self.timeit(number))
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1407 return min(times) / number
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1408
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1409 def main():
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1410 (options, test_names) = parser.parse_args()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1411 if options.bytes_only and options.unicode_only:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1412 raise SystemExit("Only one of --8-bit and --unicode are allowed")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1413
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1414 bench_functions = []
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1415 for (k,v) in globals().items():
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1416 if hasattr(v, "is_bench"):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1417 if test_names:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1418 for name in test_names:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1419 if name in v.group:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1420 break
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1421 else:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1422 # Not selected, ignore
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1423 continue
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1424 if options.skip_re and hasattr(v, "uses_re"):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1425 continue
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1426
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1427 bench_functions.append( (v.group, k, v) )
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1428 bench_functions.sort()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1429
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1430 p("bytes\tunicode")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1431 p("(in ms)\t(in ms)\t%\tcomment")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1432
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1433 bytes_total = uni_total = 0.0
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1434
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1435 for title, group in itertools.groupby(bench_functions,
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1436 operator.itemgetter(0)):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1437 # Flush buffer before each group
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1438 sys.stdout.flush()
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1439 p("="*10, title)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1440 for (_, k, v) in group:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1441 if hasattr(v, "is_bench"):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1442 bytes_time = 0.0
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1443 bytes_time_s = " - "
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1444 if not options.unicode_only:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1445 try:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1446 bytes_time = BenchTimer("__main__.%s(__main__.BYTES)" % (k,),
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1447 "import __main__").best(REPEAT)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1448 bytes_time_s = "%.2f" % (1000 * bytes_time)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1449 bytes_total += bytes_time
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1450 except UnsupportedType:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1451 bytes_time_s = "N/A"
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1452 uni_time = 0.0
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1453 uni_time_s = " - "
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1454 if not options.bytes_only:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1455 try:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1456 uni_time = BenchTimer("__main__.%s(__main__.UNICODE)" % (k,),
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1457 "import __main__").best(REPEAT)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1458 uni_time_s = "%.2f" % (1000 * uni_time)
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1459 uni_total += uni_time
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1460 except UnsupportedType:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1461 uni_time_s = "N/A"
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1462 try:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1463 average = bytes_time/uni_time
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1464 except (TypeError, ZeroDivisionError):
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1465 average = 0.0
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1466 p("%s\t%s\t%.1f\t%s (*%d)" % (
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1467 bytes_time_s, uni_time_s, 100.*average,
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1468 v.comment, v.repeat_count))
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1469
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1470 if bytes_total == uni_total == 0.0:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1471 p("That was zippy!")
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1472 else:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1473 try:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1474 ratio = bytes_total/uni_total
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1475 except ZeroDivisionError:
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1476 ratio = 0.0
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1477 p("%.2f\t%.2f\t%.1f\t%s" % (
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1478 1000*bytes_total, 1000*uni_total, 100.*ratio,
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1479 "TOTAL"))
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1480
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1481 if __name__ == "__main__":
704630a9c5d5 Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1482 main()