View difference between Paste ID: n6sEEZQ6 and r44rKdLx
SHOW: | | - or go back to the newest paste.
1
def foo():
2
    x = 0
3
    y = 0
4
    for i in xrange(1000000):
5
        for xi, yi in [(x-1,y-1),(x,y-1),(x+1,y-1),(x-1,y),(x+1,y),(x-1,y+1),(x,y+1),(x+1,y+1)]:
6
            z = xi + yi
7
def bar():
8
    x = 0
9
    y = 0
10
    for i in xrange(1000000):
11-
        for dx, dy in [(-1,-1),(0,-1),(y,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]:
11+
        for dx, dy in [(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]:
12
            xi = x + dx
13
            yi = y + dy
14
            z = xi + yi
15
            
16
import time 
17
start = time.time()
18
foo()
19
print "foo took %.3fs" % (time.time() - start)
20
start = time.time()
21
bar()
22
print "bar took %.3fs" % (time.time() - start)
23
24
# Prints:
25-
# foo took 1.683s
25+
# foo took 1.680s
26-
# bar took 1.623s
26+
# bar took 1.563s