Skip to content

Commit 96d4370

Browse files
committed
Feature: Add options to benchmark script to set iterations and enable foundation foods.
1 parent d9487a4 commit 96d4370

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

benchmark.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/usr/bin/env python3
2+
import argparse
23
import time
34

45
from ingredient_parser import parse_ingredient
56

6-
ITERATIONS = 500
7-
87
if __name__ == "__main__":
98
sentences = [
109
("½ cup warm water (105°F)", "0.5 cup warm water (105°F)"),
@@ -44,12 +43,23 @@
4443
),
4544
]
4645

46+
parser = argparse.ArgumentParser(description="Ingredient Parser benchmark")
47+
parser.add_argument(
48+
"--iterations", "-i", type=int, help="Number of iterations to run.", default=500
49+
)
50+
parser.add_argument(
51+
"--foundationfoods", "-ff", action="store_true", help="Enable foundation foods."
52+
)
53+
args = parser.parse_args()
54+
4755
start = time.time()
48-
for i in range(ITERATIONS):
56+
for i in range(args.iterations):
4957
for sent, _ in sentences:
50-
parse_ingredient(sent, expect_name_in_output=True)
58+
parse_ingredient(
59+
sent, expect_name_in_output=True, foundation_foods=args.foundationfoods
60+
)
5161

52-
total_sentences = ITERATIONS * len(sentences)
62+
total_sentences = args.iterations * len(sentences)
5363
duration = time.time() - start
5464
print(f"Elapsed time: {duration:.2f} s")
5565
print(f"{1e6 * duration / total_sentences:.2f} us/sentence")

0 commit comments

Comments
 (0)