Skip to content

Instantly share code, notes, and snippets.

@nfd
Last active August 29, 2015 14:20
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 nfd/bbdf94f0b21d75cc049a to your computer and use it in GitHub Desktop.
Save nfd/bbdf94f0b21d75cc049a to your computer and use it in GitHub Desktop.
Linux benchmark for CI20-os demonstration
#include <sys/time.h>
#include <inttypes.h>
#include <stdio.h>
uint32_t ms(struct timeval *from, struct timeval *to)
{
uint32_t from_ms, to_ms;
from_ms = (from->tv_sec * 1000) + (from->tv_usec / 1000);
to_ms = (to->tv_sec * 1000) + (to->tv_usec / 1000);
return to_ms - from_ms;
}
int main(int argc, char **argv)
{
int run;
struct timeval prev, cur;
for(run = 0; run < 3; run ++) {
volatile uint32_t i;
gettimeofday(&prev, 0);
for(i = 0; i < 0xfffffff; i++)
;
gettimeofday(&cur, 0);
printf("%04x\n", ms(&prev, &cur));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment