Skip to content

Instantly share code, notes, and snippets.

@joemccall86
Created October 28, 2019 12:29
Show Gist options
  • Select an option

  • Save joemccall86/c441119a88b88dcd2010068d9e557487 to your computer and use it in GitHub Desktop.

Select an option

Save joemccall86/c441119a88b88dcd2010068d9e557487 to your computer and use it in GitHub Desktop.

Revisions

  1. joemccall86 created this gist Oct 28, 2019.
    32 changes: 32 additions & 0 deletions calloc_test.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #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;
    }