Mercurial > cpython-lru_cache-weakref
annotate Tools/stringbench/README @ 84007:dbfbdf2b5c19 3.3
Fix #17967: For ftp urls CWD to target instead of hopping to each directory
towards target. This fixes a bug where target is accessible, but parent
directories are restricted.
| author | Senthil Kumaran <senthil@uthcode.com> |
|---|---|
| date | Sat, 01 Jun 2013 08:27:06 -0700 |
| parents | 704630a9c5d5 |
| children |
| 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 stringbench is a set of performance tests comparing byte string |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
2 operations with unicode operations. The two string implementations |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
3 are loosely based on each other and sometimes the algorithm for one is |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
4 faster than the other. |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
5 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
6 These test set was started at the Need For Speed sprint in Reykjavik |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
7 to identify which string methods could be sped up quickly and to |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
8 identify obvious places for improvement. |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
9 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
10 Here is an example of a benchmark |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
11 |
|
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 @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
|
14 def startswith_single(STR): |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
15 s1 = STR("Andrew") |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
16 s2 = STR("A") |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
17 s1_startswith = s1.startswith |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
18 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
|
19 s1_startswith(s2) |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
20 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
21 The bench decorator takes three parameters. The first is a short |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
22 description of how the code works. In most cases this is Python code |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
23 snippet. It is not the code which is actually run because the real |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
24 code is hand-optimized to focus on the method being tested. |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
25 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
26 The second parameter is a group title. All benchmarks with the same |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
27 group title are listed together. This lets you compare different |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
28 implementations of the same algorithm, such as "t in s" |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
29 vs. "s.find(t)". |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
30 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
31 The last is a count. Each benchmark loops over the algorithm either |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
32 100 or 1000 times, depending on the algorithm performance. The output |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
33 time is the time per benchmark call so the reader needs a way to know |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
34 how to scale the performance. |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
35 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
36 These parameters become function attributes. |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
37 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
38 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
39 Here is an example of the output |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
40 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
41 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
42 ========== count newlines |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
43 38.54 41.60 92.7 ...text.with.2000.newlines.count("\n") (*100) |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
44 ========== early match, single character |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
45 1.14 1.18 96.8 ("A"*1000).find("A") (*1000) |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
46 0.44 0.41 105.6 "A" in "A"*1000 (*1000) |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
47 1.15 1.17 98.1 ("A"*1000).index("A") (*1000) |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
48 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
49 The first column is the run time in milliseconds for byte strings. |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
50 The second is the run time for unicode strings. The third is a |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
51 percentage; byte time / unicode time. It's the percentage by which |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
52 unicode is faster than byte strings. |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
53 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
54 The last column contains the code snippet and the repeat count for the |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
55 internal benchmark loop. |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
56 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
57 The times are computed with 'timeit.py' which repeats the test more |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
58 and more times until the total time takes over 0.2 seconds, returning |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
59 the best time for a single iteration. |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
60 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
61 The final line of the output is the cumulative time for byte and |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
62 unicode strings, and the overall performance of unicode relative to |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
63 bytes. For example |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
64 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
65 4079.83 5432.25 75.1 TOTAL |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
66 |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
67 However, this has no meaning as it evenly weights every test. |
|
704630a9c5d5
Issue #13165: stringbench is now available in the Tools/stringbench folder.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
68 |
