Skip to content

Commit

Permalink
Add benchmark for low accuracy mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pemistahl committed Sep 6, 2022
1 parent b27eea7 commit b1df06b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions scripts/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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()

0 comments on commit b1df06b

Please sign in to comment.