Skip to content

Commit aa85f71

Browse files
committed
Cleaned up profiler code
1 parent f16b644 commit aa85f71

File tree

2 files changed

+14
-42
lines changed

2 files changed

+14
-42
lines changed

profile.py

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sc2reader import Replay
88

99
def 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()

test_replays/test_all.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os, sys
55
import pytest
66

7-
#sys.path.append(os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../")))
87
sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../")))
98

109
from sc2reader import Replay
@@ -122,7 +121,7 @@ def test_ffa():
122121
# Unknown result is the best we can do.
123122
print replay.length
124123
print replay.events[-2]
125-
assert replay.winner_known == True
124+
assert replay.winner_known == False
126125

127126
def test_unknown_winner():
128127
replay = Replay("test_replays/build17811/10.SC2Replay")
@@ -148,7 +147,6 @@ def test_us_realm():
148147
assert replay.player['ShadesofGray'].url == "http://us.battle.net/sc2/en/profile/2358439/1/ShadesofGray/"
149148
assert replay.player['reddawn'].url == "http://us.battle.net/sc2/en/profile/2198663/1/reddawn/"
150149

151-
# We can be really proud: phpsc2replay fails with the messages!
152150
def test_kr_realm_and_tampered_messages():
153151
replay = Replay("test_replays/build17811/11.SC2Replay")
154152
assert replay.player['명지대학교'].url == "http://kr.battle.net/sc2/en/profile/258945/1/명지대학교/"

0 commit comments

Comments
 (0)