-
Notifications
You must be signed in to change notification settings - Fork 5
/
concat_benchmark.py
executable file
·48 lines (34 loc) · 1.23 KB
/
concat_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
#!/usr/bin/python3
import libmyrustlib
import libmynimlib
iterations = 1000
def concat_basic(iterations):
output = ""
for num in range(iterations):
output += str(num)
return output
def concat_join(iterations):
output = []
for num in range(iterations):
output.append(str(num))
return "".join(output)
def concat_comprehensions(iterations):
return "".join([str(num) for num in range(iterations)])
def test_concat_basic(benchmark):
benchmark(concat_basic, iterations)
def test_concat_join(benchmark):
benchmark(concat_join, iterations)
def test_concat_comprehensions(benchmark):
benchmark(concat_comprehensions, iterations)
def test_concat_rust(benchmark):
benchmark(libmyrustlib.rust_concat, iterations)
def test_concat_rust_reserve(benchmark):
benchmark(libmyrustlib.rust_concat_reserve, iterations)
def test_concat_rust_logdigits(benchmark):
benchmark(libmyrustlib.rust_concat_logdigits, iterations)
def test_concat_rust_buffer(benchmark):
benchmark(libmyrustlib.rust_concat_buffer, iterations)
def test_concat_rust_inplace(benchmark):
benchmark(libmyrustlib.rust_concat_inplace, iterations)
def test_concat_nim(benchmark):
benchmark(libmynimlib.nim_concat, iterations)