-
-
Save boppreh/e9110afa1077c6329de3f47041e90646 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
int main() { | |
int count = 0; | |
for (int i = 0; i < 1000000000; i++) { | |
count += 1; | |
// Prevent the compiler from just optimizing the entire loop away. | |
asm(""); | |
if (count % 100000000 == 0) | |
printf(".", count); | |
} | |
return 0; | |
} | |
/* | |
$ gcc -O3 count.c -o count.exe && time ./count.exe | |
.......... | |
real 0m0.523s | |
user 0m0.000s | |
sys 0m0.015s | |
*/ |
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
count = 0 | |
for i in range(1_000_000_000): | |
count += 1 | |
if count % 100_000_000 == 0: | |
print('.', end='') | |
# $ time python count.py | |
# .......... | |
# real 1m42.761s | |
# user 0m0.015s | |
# sys 0m0.000s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment