-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbench.py
61 lines (41 loc) · 1.47 KB
/
bench.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
from multiprocessing import Pool, cpu_count
from pyheck import snake, snake_many
from inflection import underscore
def inflection_underscore_multiprocessing(strings: list[str]) -> list[str]:
try:
workers = cpu_count()
except NotImplementedError:
workers = 1
pool = Pool(processes=workers)
return pool.map(underscore, strings)
def snake_multiprocessing(strings: list[str]) -> list[str]:
try:
workers = cpu_count()
except NotImplementedError:
workers = 1
pool = Pool(processes=workers)
return pool.map(snake, strings)
def test_snake(benchmark):
val = "DeviceType"
benchmark(snake, val)
def test_inflection_underscore(benchmark):
val = "DeviceType"
benchmark(underscore, val)
def test_snake_long_sentence(benchmark):
val = "DeviceType" * 100_000
benchmark(snake, val)
def test_inflection_underscore_long_sentence(benchmark):
val = "DeviceType" * 100_000
benchmark(underscore, val)
def test_inflection_underscore_many(benchmark):
val = ["DeviceType"] * 100_000
benchmark(lambda lst: [underscore(x) for x in lst], val)
def test_snake_multiprocessing(benchmark):
val = ["DeviceType"] * 100_000
benchmark(snake_multiprocessing, val)
def test_snake_many(benchmark):
val = ["DeviceType"] * 100_000
benchmark(snake_many, val)
def test_inflection_underscore_multiprocessing(benchmark):
val = ["DeviceType"] * 100_000
benchmark(inflection_underscore_multiprocessing, val)