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