Exemple #1
0
import hack
import mx.Tools.NewBuiltins

a = trange(10000)

def f1():

    x = (a,a,a)
    for i in trange(100):
        x = lists(x)

def f2():

    x = (a,a,a)
    for i in trange(100):
        x = tuples(x)

def f3(apply=apply,map=map,tuple=tuple):

    x = (a,a,a)
    y = None
    for i in trange(100):
        x = apply(map,(y,)+tuple(x))

print 'lists:',hack.clock('f1()')
print 'tuples:',hack.clock('f2()')
print 'map:',hack.clock('f3()')
Exemple #2
0
    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)
import mx.Tools.NewBuiltins

a = trange(10000)


def f1():

    x = (a, a, a)
    for i in trange(100):
        x = lists(x)


def f2():

    x = (a, a, a)
    for i in trange(100):
        x = tuples(x)


def f3(apply=apply, map=map, tuple=tuple):

    x = (a, a, a)
    y = None
    for i in trange(100):
        x = apply(map, (y, ) + tuple(x))


print 'lists:', hack.clock('f1()')
print 'tuples:', hack.clock('f2()')
print 'map:', hack.clock('f3()')
Exemple #4
0

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)