Пример #1
0
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
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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
Пример #6
0
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
Пример #7
0
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
Пример #8
0
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
Пример #9
0
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