File: multilang.py

package info (click to toggle)
haskell-text 1.2.0.6-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 900 kB
  • sloc: haskell: 9,299; ansic: 238; python: 87; ruby: 84; sh: 49; makefile: 29
file content (50 lines) | stat: -rwxr-xr-x 1,030 bytes parent folder | download | duplicates (6)
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
50
#!/usr/bin/env python

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 xrange(3):
        start = time.time()
        for j in xrange(count):
            g()
        a = min(a, (time.time() - start) / count)

    b = 1e300
    for i in xrange(3):
        start = time.time()
        for j in xrange(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()
contents = contents.decode('utf-8')

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()