You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can make Python about 2x faster with these changes:
values= [value%maxIntforvalueinxrange(warmUpIterations)]
values= [(value, value*2, value+1) forvalueinvalues]
map_get=map.get# for i in xrange(warmUpIterations):# num1 = i % maxInt# num2 = num1 * 2# num3 = num1 + 1fornum1, num2, num3invalues:
map[num1] =num2value=map_get(num3)
# if value:# # Make sure we do something with the result so that it is not optimized away# sum += value
What changed:
Move the math out of the loop. You want to test hash table performance not integer math.
Replace map.get with map_get to avoid the method lookup.
Skip summing values. Python's dead-code optimizations are not very aggressive. The loop will stay.
The text was updated successfully, but these errors were encountered:
You can make Python about 2x faster with these changes:
What changed:
map.get
withmap_get
to avoid the method lookup.The text was updated successfully, but these errors were encountered: