From b1df06bc6403acbbde95c816837b9d12d26fcf46 Mon Sep 17 00:00:00 2001 From: "Peter M. Stahl" Date: Tue, 6 Sep 2022 22:02:03 +0200 Subject: [PATCH] Add benchmark for low accuracy mode --- scripts/benchmark.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/benchmark.py b/scripts/benchmark.py index 2d01e465..dc833574 100755 --- a/scripts/benchmark.py +++ b/scripts/benchmark.py @@ -16,14 +16,27 @@ import timeit -def benchmark_preloading_all_language_models(): +def benchmark_preloading_all_language_models_in_low_accuracy_mode(): setup = "from lingua import LanguageDetectorBuilder" stmt = """LanguageDetectorBuilder\ .from_all_languages()\ + .with_low_accuracy_mode()\ .with_preloaded_language_models()\ .build()""" - print("Measuring time to preload all language models...") + print("Measuring time to preload all language models in low accuracy mode...") + result = timeit.timeit(setup=setup, stmt=stmt, number=1) + print(f"Time: {result:.2f} seconds") + + +def benchmark_preloading_all_language_models_in_high_accuracy_mode(): + setup = "from lingua import LanguageDetectorBuilder" + stmt = """LanguageDetectorBuilder\ + .from_all_languages()\ + .with_preloaded_language_models()\ + .build()""" + + print("Measuring time to preload all language models in high accuracy mode...") result = timeit.timeit(setup=setup, stmt=stmt, number=1) print(f"Time: {result:.2f} seconds") @@ -55,7 +68,9 @@ def benchmark_language_detection(): if __name__ == "__main__": - benchmark_preloading_all_language_models() + benchmark_preloading_all_language_models_in_low_accuracy_mode() + print() + benchmark_preloading_all_language_models_in_high_accuracy_mode() print() benchmark_language_detection() print()