Skip to content

Instantly share code, notes, and snippets.

Created Jun 15, 2011
What would you like to do?
#!/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