Add benchmarking logic for memory, wer and speed (#773)
This commit is contained in:
31
benchmark/speed_benchmark.py
Normal file
31
benchmark/speed_benchmark.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import argparse
|
||||
import timeit
|
||||
|
||||
from typing import Callable
|
||||
|
||||
from utils import inference
|
||||
|
||||
parser = argparse.ArgumentParser(description="Speed benchmark")
|
||||
parser.add_argument(
|
||||
"--repeat",
|
||||
type=int,
|
||||
default=3,
|
||||
help="Times an experiment will be run.",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
def measure_speed(func: Callable[[], None]):
|
||||
# as written in https://docs.python.org/3/library/timeit.html#timeit.Timer.repeat,
|
||||
# min should be taken rather than the average
|
||||
runtimes = timeit.repeat(
|
||||
func,
|
||||
repeat=args.repeat,
|
||||
number=10,
|
||||
)
|
||||
print(runtimes)
|
||||
print("Min execution time: %.3fs" % (min(runtimes) / 10.0))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
measure_speed(inference)
|
||||
Reference in New Issue
Block a user