77from sc2reader import Replay
88
99def parse_replays ():
10+ # Run four times to dampen noise
1011 for run in range (1 ,4 ):
1112 file_list = []
1213 rootdir = "test_replays/build17811/"
@@ -20,45 +21,18 @@ def parse_replays():
2021 print file
2122 replay = Replay (file )
2223
23- # Problem with the profiler is that it adds conciderable amount of overhead
24- # cProfile.run("parse_replays()","replay_profile")
25- # stats = Stats("replay_profile")
26- # stats.strip_dirs().sort_stats("time").print_stats(30)
24+ # Use the results of this function when comparing performance with other libraries.
25+ def benchmark_with_timetime ():
26+ start = time .time ()
27+ parse_replays ()
28+ diff = time .time () - start
29+ print diff
2730
28- start = time . time ()
29- parse_replays ()
30- diff = time . time () - start
31- print diff
31+ def profile ():
32+ cProfile . run ( " parse_replays()" , "replay_profile" )
33+ stats = Stats ( "replay_profile" )
34+ stats . strip_dirs (). sort_stats ( "time" ). print_stats ( 30 )
3235
33- # ========================================
34- # Results for March 1 2011
35- # With cProfile
3636
37- # Tue Mar 1 06:25:22 2011 replay_profile
38- #
39- # 20568477 function calls (20565106 primitive calls) in 37.650 seconds
40- #
41- # Ordered by: internal time
42- # List reduced from 184 to 15 due to restriction <15>
43- #
44- # ncalls tottime percall cumtime percall filename:lineno(function)
45- # 3484431 7.903 0.000 8.559 0.000 utils.py:42(get_big)
46- # 3057363 5.960 0.000 13.308 0.000 utils.py:89(get_big_int)
47- # 33 4.828 0.146 35.395 1.073 parsers.py:225(load)
48- # 472272 2.948 0.000 3.360 0.000 objects.py:98(__init__)
49- # 42861 2.227 0.000 6.391 0.000 eventparsers.py:154(load)
50- # 472272 2.222 0.000 3.223 0.000 parsers.py:254(get_parser)
51- # 114174 1.225 0.000 4.265 0.000 eventparsers.py:50(load)
52- # 294732 1.224 0.000 3.983 0.000 eventparsers.py:394(load)
53- # 473916 1.060 0.000 3.568 0.000 utils.py:108(get_timestamp)
54- # 1142493 0.926 0.000 0.926 0.000 utils.py:66(peek)
55- # 3965823 0.745 0.000 0.745 0.000 {len}
56- # 7095 0.705 0.000 0.705 0.000 {method 'upper' of 'str' objects}
57- # 695461 0.644 0.000 0.644 0.000 {range}
58- # 1 0.575 0.575 37.571 37.571 profile.py:9(parse_replays)
59- # 566628 0.491 0.000 0.491 0.000 {method 'rjust' of 'str' objects}
60-
61-
62- # With time.time()
63- # 28.2304489613
64- # ========================================
37+ benchmark_with_timetime ()
38+ #profile()
0 commit comments