Skip to content

Instantly share code, notes, and snippets.

@stepancheg
Created January 23, 2010 02:36
Show Gist options
  • Save stepancheg/284385 to your computer and use it in GitHub Desktop.
Save stepancheg/284385 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdint.h>
const uint64_t count = 1000 * 1000 * 1000;
static uint64_t microseconds() {
struct timeval tv;
if (0 != gettimeofday(&tv, NULL))
abort();
return 1LL * 1000000 * tv.tv_sec + tv.tv_usec;
}
int main() {
for (;;) {
uint64_t sum = 0;
uint64_t start = microseconds();
for (uint64_t i = 0; i < count; ++i) {
sum += i;
}
uint64_t d = microseconds() - start;
printf("%lldus\n", (long long) d);
printf("%lld\n", (long long) sum);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment