MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / benchmark_levenshtein_distance

Function benchmark_levenshtein_distance

strings/levenshtein_distance.py:99–111  ·  view source on GitHub ↗

Benchmark the Levenshtein distance function. :param str: The name of the function being benchmarked. :param func: The function to be benchmarked.

(func: Callable)

Source from the content-addressed store, hash-verified

97
98
99def benchmark_levenshtein_distance(func: Callable) -> None:
100 """
101 Benchmark the Levenshtein distance function.
102 :param str: The name of the function being benchmarked.
103 :param func: The function to be benchmarked.
104 """
105 from timeit import timeit
106
107 stmt = f"{func.__name__}('sitting', 'kitten')"
108 setup = f"from __main__ import {func.__name__}"
109 number = 25_000
110 result = timeit(stmt=stmt, setup=setup, number=number)
111 print(f"{func.__name__:<30} finished {number:,} runs in {result:.5f} seconds")
112
113
114if __name__ == "__main__":

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected