Create a gist now

Instantly share code, notes, and snippets.

@nfd /benchmark.c
Last active Aug 29, 2015

What would you like to do?
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