Last active
March 1, 2022 02:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
0.002358353853225708s on Dell Vostro 5502