File: multilang.py

package info (click to toggle)
ghc 9.0.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 177,780 kB
  • sloc: haskell: 494,441; ansic: 70,262; javascript: 9,423; sh: 8,537; python: 2,646; asm: 1,725; makefile: 1,333; xml: 196; cpp: 167; perl: 143; ruby: 84; lisp: 7
file content (49 lines) | stat: -rwxr-xr-x 992 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3

import math
import sys
import time

def find_first():
    cf = contents.find
    return timer(lambda: cf("en:Benin"))

def timer(f, count=100):
    a = 1e300
    def g():
        return
    for i in range(3):
        start = time.time()
        for j in range(count):
            g()
        a = min(a, (time.time() - start) / count)

    b = 1e300
    for i in range(3):
        start = time.time()
        for j in range(count):
            f()
        b = min(b, (time.time() - start) / count)

    return round(b - a, int(round(math.log(count, 10) - math.log(b - a, 10))))

contents = open('../../tests/text-test-data/yiwiki.xml', 'r').read()

benchmarks = (
    find_first,
    )

to_run = sys.argv[1:]
bms = []
if to_run:
    for r in to_run:
        for b in benchmarks:
            if b.__name__.startswith(r):
                bms.append(b)
else:
    bms = benchmarks

for b in bms:
    sys.stdout.write(b.__name__ + ' ')
    sys.stdout.flush()
    print(b())