File: bench1.py

package info (click to toggle)
egenix-mx-base 3.2.8-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,420 kB
  • ctags: 6,208
  • sloc: ansic: 22,304; python: 18,124; sh: 137; makefile: 121
file content (44 lines) | stat: -rw-r--r-- 952 bytes parent folder | download | duplicates (8)
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
import hack
import mx.Tools.NewBuiltins

k = range(10000)
l = range(1,10001)
loops = trange(100)

def f(k=k,l=l,tuples=tuples,loops=loops):
    for i in loops:
        for a,b in tuples(k,l):
            pass

def f1(k=k,l=l,lists=lists,loops=loops):
    for i in loops:
        for a,b in lists(k,l):
            pass

def g(k=k,l=l,map=map,loops=loops):
    for i in loops:
        for a,b in map(None,k,l):
            pass

def h(k=k,l=l,indices=indices,len=len,loops=loops):
    for i in loops:
        for i in indices(k):
            a,b = k[i], l[i]

print 'with tuples():',
hack.clock('f()')
print 'with lists():',
hack.clock('f1()')
print 'with map():',
hack.clock('g()')
print 'indexed:',
hack.clock('h()')
print 'map(None,...):',
hack.clock('apply(map,(None,)+(k,)*100)')
print 'tuples(...):',
hack.clock('tuples((k,)*100)')
print 'lists(...):',
hack.clock('lists((k,)*100)')

# Check
assert apply(map,(None,)+(k,)*100) == tuples((k,)*100)