Skip to content

Instantly share code, notes, and snippets.

@joemccall86
Created October 28, 2019 12:29
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 joemccall86/c441119a88b88dcd2010068d9e557487 to your computer and use it in GitHub Desktop.
Save joemccall86/c441119a88b88dcd2010068d9e557487 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <microtime.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int i, vector_size = 200000000;
float *vector1, *vector2;
double time1, time2;
/* allocate and set to zero */
time1 = microtime();
vector1 = calloc(vector_size, sizeof(float));
time2 = microtime();
printf("1. Time = %g us\tTimer Resolution = %g us\n", time2-time1, get_microtime_resolution());
time1 = microtime();
vector2 = malloc(vector_size * sizeof(float));
for (i = 0; i < vector_size; ++i) {
vector2[i] = 0;
}
time2 = microtime();
printf("2. Time = %g us\tTimer Resolution = %g us\n", time2-time1, get_microtime_resolution());
/* cleanup */
free(vector1);
free(vector2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment