Created
January 23, 2010 02:36
-
-
Save stepancheg/284385 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#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