Last active
August 29, 2015 13:57
-
-
Save blackrobot/9636690 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import timeit | |
ITERATIONS = 10000 | |
COMPLEXITY = 3 | |
SIZE = 1000 | |
def filter_zero(row): | |
return 0 in row | |
def filter_one(row): | |
return 1 in row | |
def attila(data): | |
for i, d in enumerate(data): | |
if not filter_zero(d): | |
data.pop(i) | |
for i, d in enumerate(data): | |
if not filter_one(d): | |
data.pop(i) | |
return list(data) | |
def damon(data): | |
for i, d in enumerate(data): | |
if not filter_zero(d) or filter_one(d): | |
data.pop(i) | |
return list(data) | |
if __name__ == '__main__': | |
choices = range(9) | |
data_set = [ | |
(random.choice(choices) for c in range(COMPLEXITY)) | |
for _ in range(SIZE) | |
] | |
data_str = "[%s]" % ', '.join( | |
["(%s)" % ','.join(str(a) for a in d) for d in data_set] | |
) | |
attila_result = timeit.timeit( | |
'attila(%s)' % data_str, | |
number=ITERATIONS, | |
setup='from __main__ import attila', | |
) | |
print "Finished with Attila..." | |
damon_result = timeit.timeit( | |
'damon(%s)' % data_str, | |
number=ITERATIONS, | |
setup='from __main__ import damon', | |
) | |
print "Finished with Damon..." | |
print "" | |
print "Attila:\t", attila_result | |
print "Damon:\t", damon_result | |
print "Winner", "Damon" if damon_result < attila_result else "Attila" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment