-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark.py
77 lines (61 loc) · 1.81 KB
/
benchmark.py
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
76
77
import subprocess
import dataclasses
import time
import pyarkbench
@dataclasses.dataclass
class Result:
duration: float
size: int
@dataclasses.dataclass
class TestCase:
description: str
text: str
def run(self):
pyarkbench.cleanup()
with pyarkbench.Timer() as base64_timer:
base64_result = subprocess.run(
"base64", input=self.text.encode("utf-8"), stdout=subprocess.PIPE
)
base64_len = len(base64_result.stdout)
pyarkbench.cleanup()
with pyarkbench.Timer() as baseMEOW_timer:
# baseMEOW_result = subprocess.run(
# "baseMEOW", input=self.text.encode("utf-8"), stdout=subprocess.PIPE
# )
baseMEOW_result = subprocess.run(
"./meow", input=self.text.encode("utf-8"), stdout=subprocess.PIPE
)
baseMEOW_len = len(baseMEOW_result.stdout)
return Result(base64_timer.ms_duration, base64_len), Result(
baseMEOW_timer.ms_duration, baseMEOW_len
)
tests = [
TestCase("10 characters", "a" * 10),
TestCase("1000 characters", "a" * 1000),
TestCase("10000 characters", "a" * 10000),
TestCase("1000000 characters", "a" * 1000000),
]
table = [
[
"test case",
"base64 runtime (ms)",
"baseMEOW runtime (ms)",
"base64 size (bytes)",
"baseMEOW size (bytes)",
]
]
table.append(["---" for _ in table[0]])
for test in tests:
base64_result, baseMEOW_result = test.run()
table.append(
[
test.description,
round(base64_result.duration, 2),
round(baseMEOW_result.duration, 2),
base64_result.size,
baseMEOW_result.size,
]
)
test.run()
for row in table:
print("|".join([str(x) for x in row]))