Last active
August 29, 2015 13:59
-
-
Save jen20/10676511 to your computer and use it in GitHub Desktop.
UUIDS benchmark
This file contains 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
$ ./uuids | |
Completed test with libuuid: | |
Iterations: 10,000,000 | |
Duration: 786.47ms (786,467,499ns) | |
Completed test with libuuid: | |
Iterations: 10,000,000 | |
Duration: 723.36ms (723,363,115ns) | |
Completed test with libuuid: | |
Iterations: 10,000,000 | |
Duration: 742.35ms (742,345,965ns) | |
Completed test with libuuid: | |
Iterations: 10,000,000 | |
Duration: 744.85ms (744,854,664ns) | |
Completed test with libuuid: | |
Iterations: 10,000,000 | |
Duration: 732.54ms (732,540,515ns) | |
Completed test with libuuid: | |
Iterations: 10,000,000 | |
Duration: 733.92ms (733,923,711ns) | |
Completed test with libuuid: | |
Iterations: 10,000,000 | |
Duration: 746.95ms (746,954,394ns) | |
Completed test with libuuid: | |
Iterations: 10,000,000 | |
Duration: 755.41ms (755,414,933ns) | |
Completed test with libuuid: | |
Iterations: 10,000,000 | |
Duration: 721.64ms (721,635,948ns) | |
Completed test with libuuid: | |
Iterations: 10,000,000 | |
Duration: 789.27ms (789,273,394ns) | |
Completed test with czmq: | |
Iterations: 10,000,000 | |
Duration: 2,319.04ms (2,319,042,823ns) | |
Completed test with czmq: | |
Iterations: 10,000,000 | |
Duration: 2,245.59ms (2,245,594,451ns) | |
Completed test with czmq: | |
Iterations: 10,000,000 | |
Duration: 2,392.85ms (2,392,853,328ns) | |
Completed test with czmq: | |
Iterations: 10,000,000 | |
Duration: 2,163.37ms (2,163,374,426ns) | |
Completed test with czmq: | |
Iterations: 10,000,000 | |
Duration: 2,245.26ms (2,245,258,416ns) | |
Completed test with czmq: | |
Iterations: 10,000,000 | |
Duration: 2,154.82ms (2,154,823,069ns) | |
Completed test with czmq: | |
Iterations: 10,000,000 | |
Duration: 2,402.06ms (2,402,059,454ns) | |
Completed test with czmq: | |
Iterations: 10,000,000 | |
Duration: 2,348.57ms (2,348,565,065ns) | |
Completed test with czmq: | |
Iterations: 10,000,000 | |
Duration: 2,444.48ms (2,444,483,154ns) | |
Completed test with czmq: | |
Iterations: 10,000,000 | |
Duration: 2,123.31ms (2,123,305,210ns) | |
Average libuuid run: 747.68ms (747,677,413ns) | |
Average czmq run: 2,283.94ms (2,283,935,939ns) |
This file contains 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 <locale.h> | |
#include <stdint.h> | |
#include <uuid/uuid.h> | |
#include <mach/mach_time.h> | |
#include <czmq.h> | |
#define ITERATIONS 10000000 | |
#define CYCLES 10 | |
typedef struct { | |
size_t iterations; | |
int64_t duration; | |
} uuidtest_t; | |
static mach_timebase_info_data_t timebase; | |
static uuid_t libuuid_generated[ITERATIONS]; | |
static zuuid_t *zuuid_generated[ITERATIONS]; | |
uuidtest_t run_libuuid_test(); | |
uuidtest_t run_zuuid_test(); | |
int main(int argc, char *argv[]) | |
{ | |
setlocale(LC_ALL, ""); | |
mach_timebase_info(&timebase); | |
//Using libuuid directly | |
uuidtest_t libuuid_results[CYCLES]; | |
for (size_t i = 0; i < CYCLES; i++) { | |
libuuid_results[i] = run_libuuid_test(); | |
printf("Completed test with libuuid:\n\tIterations: %'lu\n\tDuration: %'.2fms (%'lluns)\n", | |
libuuid_results[i].iterations, libuuid_results[i].duration * 1e-6, libuuid_results[i].duration); | |
} | |
//Using czmq wrapper | |
uuidtest_t czmq_results[CYCLES]; | |
for (size_t i = 0; i < CYCLES; i++) { | |
czmq_results[i] = run_zuuid_test(); | |
printf("Completed test with czmq:\n\tIterations: %'lu\n\tDuration: %'.2fms (%'lluns)\n", | |
czmq_results[i].iterations, czmq_results[i].duration * 1e-6, czmq_results[i].duration); | |
} | |
int64_t libuuid_total_duration = 0; | |
int64_t czmq_total_duration = 0; | |
for (size_t i = 0; i < CYCLES; i++) { | |
libuuid_total_duration += libuuid_results[i].duration; | |
czmq_total_duration += czmq_results[i].duration; | |
} | |
libuuid_total_duration = libuuid_total_duration / CYCLES; | |
czmq_total_duration = czmq_total_duration / CYCLES; | |
printf("\nAverage libuuid run: %'.2fms (%'lluns)\n", libuuid_total_duration * 1e-6, libuuid_total_duration); | |
printf("Average czmq run: %'.2fms (%'lluns)\n", czmq_total_duration * 1e-6, czmq_total_duration); | |
return 0; | |
} | |
uuidtest_t run_libuuid_test() | |
{ | |
int64_t libuuid_start = mach_absolute_time(); | |
for (size_t i = 0; i < ITERATIONS; i++) { | |
uuid_generate(libuuid_generated[i]); | |
} | |
int64_t libuuid_end = mach_absolute_time(); | |
uuidtest_t result; | |
result.iterations = ITERATIONS; | |
result.duration = (libuuid_end - libuuid_start) * timebase.numer / timebase.denom; | |
return result; | |
} | |
uuidtest_t run_zuuid_test() | |
{ | |
int64_t libuuid_start = mach_absolute_time(); | |
for (size_t i = 0; i < ITERATIONS; i++) { | |
zuuid_generated[i] = zuuid_new(); | |
} | |
int64_t libuuid_end = mach_absolute_time(); | |
for (size_t i = 0; i < ITERATIONS; i++) { | |
free(zuuid_generated[i]); | |
} | |
uuidtest_t result; | |
result.iterations = ITERATIONS; | |
result.duration = (libuuid_end - libuuid_start) * timebase.numer / timebase.denom; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment