Skip to content

Instantly share code, notes, and snippets.

@djrtwo
Last active March 1, 2022 02:37
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 djrtwo/434a3b0e9eaf785cdd7dec70ec561ff3 to your computer and use it in GitHub Desktop.
Save djrtwo/434a3b0e9eaf785cdd7dec70ec561ff3 to your computer and use it in GitHub Desktop.
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):
times.append(exp())
print(sum(times) / float(len(times)))
if __name__ == "__main__":
main()
@djrtwo
Copy link
Author

djrtwo commented Jun 28, 2017

Outputs "0.0422" seconds on modern macbook pro.

@tranductri2003
Copy link

0.002358353853225708s on Dell Vostro 5502

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment