Skip to content

Instantly share code, notes, and snippets.

@jul
Created September 8, 2012 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jul/3674273 to your computer and use it in GitHub Desktop.
Save jul/3674273 to your computer and use it in GitHub Desktop.
testing float vs int speed for mul, pow, xor
import sys
from time import clock
from random import randint as rand
from math import sqrt
sample = [ rand(0,(1<<16) - 1 ) for i in range(0,10000000 ) ]
fsample=map(lambda x : .0001 *x, sample)
def time_me(sample, tag,op):
start=clock()
map(op, sample)
print "%s %fs" %( tag, clock() - start)
time_me(sample,'xint', lambda i:i^0123123112312)
time_me(fsample,'xfloat',lambda i:int(i)^01234345345)
time_me(sample,'mint', lambda i:i*i*i)
time_me(fsample,'mfloat', lambda i:i*i*i)
time_me(sample,'pint', lambda i:i**3)
time_me(fsample,'pfloat',lambda i:i**3)
#xint 1.900000s
#xfloat 3.450000s
#mint 2.130000s
#mfloat 2.430000s
#pint 2.320000s
#pfloat 3.450000s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment