11import cProfile
22from pstats import Stats
3+ import time
34
45import os ,sys
56sys .path .append (os .path .dirname (os .path .abspath (__file__ )))
67from sc2reader import Replay
78
9+ def parse_replays ():
10+ for run in range (1 ,4 ):
11+ file_list = []
12+ rootdir = "test_replays/build17811/"
13+ for root , sub_folders , files in os .walk (rootdir ):
14+ for file in files :
15+ basename , extension = os .path .splitext (file )
16+ if (basename != "empty" and extension .lower () == ".sc2replay" ):
17+ file_list .append (os .path .join (root ,file ))
818
9- cProfile .run ("Replay('test_replays/build17811/1.sc2replay')" ,"replay_profile" )
19+ for file in file_list :
20+ print file
21+ replay = Replay (file )
22+
23+ # Problem with the profiler is that it adds conciderable amount of overhead
24+ cProfile .run ("parse_replays()" ,"replay_profile" )
1025stats = Stats ("replay_profile" )
1126stats .strip_dirs ().sort_stats ("time" ).print_stats (15 )
1227
13- # file_list = []
14- # rootdir = "test_replays/"
15- # for root, sub_folders, files in os.walk(rootdir):
16- # for file in files:
17- # if (os.path.splitext(file)[1].lower() == ".sc2replay"):
18- # file_list.append(os.path.join(root,file))
28+ # start = time.time()
29+ # for run in range(1,4):
30+ # parse_replays()
31+ # end = time.time() - start
32+ # print end
33+
34+ # ========================================
35+ # Results for March 1 2011
36+ # With cProfile
37+
38+ # Tue Mar 1 06:25:22 2011 replay_profile
39+ #
40+ # 20568477 function calls (20565106 primitive calls) in 37.650 seconds
1941#
20- # for file in file_list:
21- # try:
22- # replay = Replay(file)
23- # except ValueError as e:
24- # print e
25- # except ParseError as e:
26- # print e
42+ # Ordered by: internal time
43+ # List reduced from 184 to 15 due to restriction <15>
44+ #
45+ # ncalls tottime percall cumtime percall filename:lineno(function)
46+ # 3484431 7.903 0.000 8.559 0.000 utils.py:42(get_big)
47+ # 3057363 5.960 0.000 13.308 0.000 utils.py:89(get_big_int)
48+ # 33 4.828 0.146 35.395 1.073 parsers.py:225(load)
49+ # 472272 2.948 0.000 3.360 0.000 objects.py:98(__init__)
50+ # 42861 2.227 0.000 6.391 0.000 eventparsers.py:154(load)
51+ # 472272 2.222 0.000 3.223 0.000 parsers.py:254(get_parser)
52+ # 114174 1.225 0.000 4.265 0.000 eventparsers.py:50(load)
53+ # 294732 1.224 0.000 3.983 0.000 eventparsers.py:394(load)
54+ # 473916 1.060 0.000 3.568 0.000 utils.py:108(get_timestamp)
55+ # 1142493 0.926 0.000 0.926 0.000 utils.py:66(peek)
56+ # 3965823 0.745 0.000 0.745 0.000 {len}
57+ # 7095 0.705 0.000 0.705 0.000 {method 'upper' of 'str' objects}
58+ # 695461 0.644 0.000 0.644 0.000 {range}
59+ # 1 0.575 0.575 37.571 37.571 profile.py:9(parse_replays)
60+ # 566628 0.491 0.000 0.491 0.000 {method 'rjust' of 'str' objects}
61+
62+
63+ # With time.time()
64+ # 28.2304489613
65+ # ========================================
0 commit comments