lockfree.c (1134B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #include "stack.h" 5 #include "queue.h" 6 #include "ring.h" 7 #include "lru.h" 8 9 struct opts { 10 size_t threads; 11 }; 12 13 #include <getopt.h> 14 15 static int 16 parse_opts(int argc, char **argv, struct opts *opts) 17 { 18 opts->threads = 4; 19 20 int opt; 21 while ((opt = getopt(argc, argv, "ht:")) != -1) { 22 switch (opt) { 23 case 't': 24 if ((opts->threads = strtoull(optarg, NULL, 0)) == 0) 25 return -1; 26 break; 27 28 default: 29 return -1; 30 } 31 } 32 33 return 0; 34 } 35 36 static void 37 usage(char **argv) 38 { 39 fprintf(stderr, "Usage: %s [-t <threads>]\n", argv[0]); 40 } 41 42 static void 43 bench(struct opts const *opts, struct benchmark benchmark) 44 { 45 printf("%s - %zu threads:\n", benchmark.name, opts->threads); 46 printf("=========================\n"); 47 48 printf("results:\n"); 49 printf("=========================\n"); 50 51 printf("\n"); 52 } 53 54 int 55 main(int argc, char **argv) 56 { 57 struct opts opts; 58 if (parse_opts(argc, argv, &opts) < 0) { 59 usage(argv); 60 exit(EXIT_FAILURE); 61 } 62 63 bench(&opts, lf_stack_benchmark()); 64 bench(&opts, lf_queue_benchmark()); 65 bench(&opts, lf_ring_benchmark()); 66 bench(&opts, lf_lru_benchmark()); 67 68 exit(EXIT_SUCCESS); 69 }