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 _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 _search_time(expression, given, clock=_clock): p = Parser() parsed = p.parse(expression) best = float('inf') for i in range(DEFAULT_NUM_LOOP): start = clock() parsed.search(given) end = clock() total = end - start if total < best: best = total return best
def _search_time(expression, given): p = Parser() parsed = p.parse(expression) best = float('inf') for i in range(DEFAULT_NUM_LOOP): start = time.time() parsed.search(given) end = time.time() total = end - start if total < best: best = total return best
def _search_time(expression, given, clock=_clock): p = Parser() parsed = p.parse(expression) duration = 0 i = 0 while True: i += 1 start = clock() parsed.search(given) 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() 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
def get_expression_fields(jmespath_expression: str) -> Tuple[str, ...]: """Return a list of fields referenced in the given JMESPath expression. Args: jmespath_expression: The expression for which to extract a list of referenced fields. Returns: Set[str]: A set containing the names of fields referenced in the expression. """ return tuple( _get_fields(Parser().parse(jmespath_expression).parsed).keys())