Name: js-handler/node_modules/restify/node_modules/node-uuid/benchmark/benchmark-native.c
| 1: | /* |
| 2: | Test performance of native C UUID generation |
| 3: | |
| 4: | To Compile: cc -luuid benchmark-native.c -o benchmark-native |
| 5: | */ |
| 6: | |
| 7: | #include <stdio.h> |
| 8: | #include <unistd.h> |
| 9: | #include <sys/time.h> |
| 10: | #include <uuid/uuid.h> |
| 11: | |
| 12: | int main() { |
| 13: | uuid_t myid; |
| 14: | char buf[36+1]; |
| 15: | int i; |
| 16: | struct timeval t; |
| 17: | double start, finish; |
| 18: | |
| 19: | gettimeofday(&t, NULL); |
| 20: | start = t.tv_sec + t.tv_usec/1e6; |
| 21: | |
| 22: | int n = 2e5; |
| 23: | for (i = 0; i < n; i++) { |
| 24: | uuid_generate(myid); |
| 25: | uuid_unparse(myid, buf); |
| 26: | } |
| 27: | |
| 28: | gettimeofday(&t, NULL); |
| 29: | finish = t.tv_sec + t.tv_usec/1e6; |
| 30: | double dur = finish - start; |
| 31: | |
| 32: | printf("%d uuids/sec", (int)(n/dur)); |
| 33: | return 0; |
| 34: | } |
