def _parse_time(expression): best = float('inf') p = Parser() for i in range(DEFAULT_NUM_LOOP): p.purge() start = time.time() p.parse(expression) end = time.time() total = end - start if total < best: best = total return best
def _combined_time(expression, given, clock=_clock): best = float('inf') p = Parser() for i in range(DEFAULT_NUM_LOOP): p.purge() start = clock() p.parse(expression).search(given) end = clock() total = end - start if total < best: best = total return best
def _combined_time(expression, given, result, clock=_clock): best = float('inf') p = Parser() for i in range(DEFAULT_NUM_LOOP): p.purge() start = clock() r = p.parse(expression).search(given) end = clock() total = end - start if r != result: raise RuntimeError("Unexpected result, received: %s, " "expected: %s" % (r, result)) if total < best: best = total return best
def _parse_time(expression, clock=_clock): best = float('inf') p = Parser() duration = 0 i = 0 while True: i += 1 p.purge() start = clock() p.parse(expression) end = clock() total = end - start duration += total if duration >= APPROX_RUN_TIME: break return duration / i
def _combined_time(expression, given, result, clock=_clock): best = float('inf') p = Parser() duration = 0 i = 0 while True: i += 1 p.purge() start = clock() r = p.parse(expression).search(given) end = clock() total = end - start if r != result: raise RuntimeError("Unexpected result, received: %s, " "expected: %s" % (r, result)) duration += total if duration >= APPROX_RUN_TIME: break return duration / i