Skip to content

Commit 71a0fad

Browse files
committedOct 19, 2017
Simplify timing steps in bench.py
1 parent 726973e commit 71a0fad

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed
 

‎bench.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import argparse
1111
import sys
12-
import timeit
12+
import time
1313
from collections import defaultdict
1414
from io import open
1515
from os import listdir
@@ -81,7 +81,6 @@ def benchmark(chardet_mod=chardet, verbose=False, num_iters=10):
8181
get_py_impl(),
8282
sys.version))
8383
print('-' * 80)
84-
glocals = dict(globals())
8584
total_time = 0
8685
num_files = 0
8786
encoding_times = defaultdict(float)
@@ -90,10 +89,10 @@ def benchmark(chardet_mod=chardet, verbose=False, num_iters=10):
9089
num_files += 1
9190
with open(full_path, 'rb') as f:
9291
input_bytes = f.read()
93-
glocals.update(locals())
94-
bench_time = timeit.timeit('chardet_mod.detect(input_bytes)',
95-
globals=glocals,
96-
number=num_iters)
92+
start = time.time()
93+
for _ in range(num_iters):
94+
chardet_mod.detect(input_bytes)
95+
bench_time = time.time() - start
9796
if verbose:
9897
print('Average time for {}: {}s'.format(full_path,
9998
bench_time / num_iters))

0 commit comments

Comments
 (0)
Please sign in to comment.