Created
June 15, 2011 01:31
-
-
Save anonymous/1026313 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
#!/usr/bin/env python | |
from __future__ import division | |
from random import random | |
from timeit import timeit | |
def maxarg(arr): | |
counter = 0 | |
arg = 0 | |
m = arr[0] | |
for x in arr: | |
if x > m: | |
m = x | |
arg = counter | |
counter += 1 | |
return arg | |
a = [random() for i in range(10000000)] | |
print timeit('a.index(max(a))', 'from __main__ import a', number=3) | |
print timeit('maxarg(a)', 'from __main__ import a, maxarg', number=3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment