Skip to content

Commit c595911

Browse files
committed
added some performance testing and results.. sc2reader 28s, phpsc2replay 22.5s
1 parent ef3c212 commit c595911

File tree

2 files changed

+77
-14
lines changed

2 files changed

+77
-14
lines changed

profile.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
include '../sc2/phpsc2replay-1.40/mpqfile.php';
3+
include '../sc2/phpsc2replay-1.40/sc2map.php';
4+
5+
$start = microtime(true);
6+
7+
for ($i = 0; $i < 4; $i++) {
8+
$handler = opendir("test_replays/build17811/");
9+
while ($file = readdir($handler)) {
10+
if ($file != "." && $file != ".." && $file != "info.txt") {
11+
print $file."\n";
12+
$mpqfile = new MPQFile("test_replays/build17811/".$file);
13+
$replay = $mpqfile->parseReplay();
14+
}
15+
}
16+
}
17+
18+
$end = (microtime(true) - $start);
19+
print $end."\n";
20+
21+
# Results 1.3.2011
22+
# 22.587602853775
23+
24+
?>

profile.py

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,65 @@
11
import cProfile
22
from pstats import Stats
3+
import time
34

45
import os,sys
56
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
67
from 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")
1025
stats = Stats("replay_profile")
1126
stats.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

Comments
 (0)