2022-10-02 04:28:17 +00:00
|
|
|
# todo combine benchmarks of scorers into common code base
|
|
|
|
import timeit
|
2022-10-02 08:06:27 +00:00
|
|
|
|
2022-10-02 04:28:17 +00:00
|
|
|
import numpy as np
|
2022-10-02 08:06:27 +00:00
|
|
|
import pandas
|
|
|
|
|
2022-10-02 04:28:17 +00:00
|
|
|
|
|
|
|
def benchmark(name, func, setup, lengths, count):
|
|
|
|
print(f"starting {name}")
|
|
|
|
start = timeit.default_timer()
|
|
|
|
results = []
|
|
|
|
from tqdm import tqdm
|
2022-10-02 08:24:00 +00:00
|
|
|
|
2022-10-02 04:28:17 +00:00
|
|
|
for length in tqdm(lengths):
|
|
|
|
test = timeit.Timer(func, setup=setup.format(length, count))
|
|
|
|
results.append(min(test.timeit(number=1) for _ in range(7)) / count)
|
|
|
|
stop = timeit.default_timer()
|
|
|
|
print(f"finished {name}, Runtime: ", stop - start)
|
|
|
|
return results
|
|
|
|
|
2022-10-02 08:24:00 +00:00
|
|
|
|
|
|
|
setup = """
|
2022-10-02 04:28:17 +00:00
|
|
|
from rapidfuzz.distance import Jaro
|
|
|
|
import jellyfish
|
|
|
|
import string
|
|
|
|
import random
|
|
|
|
random.seed(18)
|
|
|
|
characters = string.ascii_letters + string.digits + string.whitespace + string.punctuation
|
|
|
|
a = ''.join(random.choice(characters) for _ in range({0}))
|
|
|
|
b_list = [''.join(random.choice(characters) for _ in range({0})) for _ in range({1})]
|
|
|
|
"""
|
|
|
|
|
2022-10-02 08:24:00 +00:00
|
|
|
lengths = list(range(1, 256, 4))
|
2022-10-02 04:28:17 +00:00
|
|
|
count = 4000
|
|
|
|
|
2022-10-02 08:24:00 +00:00
|
|
|
time_rapidfuzz = benchmark(
|
|
|
|
"rapidfuzz", "[Jaro.similarity(a, b) for b in b_list]", setup, lengths, count
|
|
|
|
)
|
2022-10-02 04:28:17 +00:00
|
|
|
|
|
|
|
# this gets very slow, so only benchmark it for smaller values
|
2022-10-02 08:24:00 +00:00
|
|
|
time_jellyfish = (
|
|
|
|
benchmark(
|
|
|
|
"jellyfish",
|
|
|
|
"[jellyfish.jaro_similarity(a, b) for b in b_list]",
|
|
|
|
setup,
|
|
|
|
list(range(1, 128, 4)),
|
|
|
|
count,
|
|
|
|
)
|
|
|
|
+ [np.NaN] * 32
|
|
|
|
)
|
|
|
|
|
|
|
|
df = pandas.DataFrame(
|
|
|
|
data={
|
|
|
|
"length": lengths,
|
|
|
|
"rapidfuzz": time_rapidfuzz,
|
|
|
|
"jellyfish": time_jellyfish,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
df.to_csv("results/jaro.csv", sep=",", index=False)
|