Skip to content

Instantly share code, notes, and snippets.

@djrtwo djrtwo/
Last active May 10, 2019

What would you like to do?
Time adding 1 million integers together. Run 1000 times and output average time.
import time
def exp():
adder = 0
start = time.time()
for i in range(1000000):
adder += 1
end = time.time()
return (end - start)
def main():
times = []
for i in range(1000):
print(sum(times) / float(len(times)))
if __name__ == "__main__":

This comment has been minimized.

Copy link
Owner Author

djrtwo commented Jun 28, 2017

Outputs "0.0422" seconds on modern macbook pro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.