-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-performance.py
More file actions
executable file
·77 lines (50 loc) · 1.57 KB
/
Copy pathtest-performance.py
File metadata and controls
executable file
·77 lines (50 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
import json
import codecs
import cProfile
import timeit
import jk_json
REPEATS = 20000
__parserRelaxed = jk_json.JsonParserRelaxed()
__tokenizerRelaxed = jk_json.TokenizerRelaxed()
filePath = "test-performance-test.json"
with codecs.open(filePath, "r", "utf-8") as f:
jsonTextData = f.read()
tokens = jk_json.TokenStream(__tokenizerRelaxed.tokenize(jsonTextData))
def doTestT1():
for i in range(0, REPEATS):
__tokenizerRelaxed.tokenize(jsonTextData)
#
def doTestT2():
__tokenizerRelaxed.tokenize(jsonTextData)
#
def doTestP1():
for i in range(0, REPEATS):
tokens.reset()
__parserRelaxed.parse(tokens)
#
def doTestP2():
tokens.reset()
__parserRelaxed.parse(tokens)
#
cProfile.run("doTestT1()", 'stats-tokenizing.prof')
cProfile.run("doTestP1()", 'stats-parsing.prof')
resultT = timeit.timeit(
doTestT2,
number=REPEATS
)
print("Module: Avg millis spent in " + str(REPEATS) + " tokenizings: " + str(resultT * 1000) + " ms")
resultP = timeit.timeit(
doTestP2,
number=REPEATS
)
print("Module: Avg millis spent in " + str(REPEATS) + " parsings: " + str(resultP * 1000) + " ms")
print("Module: Avg millis spent in " + str(REPEATS) + " tokenizings and parsings: " + str((resultT + resultP) * 1000) + " ms")
def doTestBuiltIn():
json.loads(jsonTextData)
result = timeit.timeit(
doTestBuiltIn,
number=REPEATS
)
print("Builtin: Avg millis spent in " + str(REPEATS) + " tokenizings and parsings: " + str(result * 1000) + " ms")
print("Builtin implementation is " + str((resultP + resultT) / result) + " times faster.")