From 71a0fad528d020c4caa053a92ee5699b78757be5 Mon Sep 17 00:00:00 2001 From: Dan Blanchard Date: Thu, 19 Oct 2017 12:22:04 -0400 Subject: [PATCH] Simplify timing steps in bench.py --- bench.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bench.py b/bench.py index 2b1148f1..eb1fbaea 100644 --- a/bench.py +++ b/bench.py @@ -9,7 +9,7 @@ import argparse import sys -import timeit +import time from collections import defaultdict from io import open from os import listdir @@ -81,7 +81,6 @@ def benchmark(chardet_mod=chardet, verbose=False, num_iters=10): get_py_impl(), sys.version)) print('-' * 80) - glocals = dict(globals()) total_time = 0 num_files = 0 encoding_times = defaultdict(float) @@ -90,10 +89,10 @@ def benchmark(chardet_mod=chardet, verbose=False, num_iters=10): num_files += 1 with open(full_path, 'rb') as f: input_bytes = f.read() - glocals.update(locals()) - bench_time = timeit.timeit('chardet_mod.detect(input_bytes)', - globals=glocals, - number=num_iters) + start = time.time() + for _ in range(num_iters): + chardet_mod.detect(input_bytes) + bench_time = time.time() - start if verbose: print('Average time for {}: {}s'.format(full_path, bench_time / num_iters))