Skip to content

Instantly share code, notes, and snippets.

@boppreh
Created May 8, 2022 11:08
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 boppreh/e9110afa1077c6329de3f47041e90646 to your computer and use it in GitHub Desktop.
Save boppreh/e9110afa1077c6329de3f47041e90646 to your computer and use it in GitHub Desktop.
#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
*/
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