| 47 | } |
| 48 | |
| 49 | static Config parseArgs(int argc, char** argv) { |
| 50 | Config config; |
| 51 | config.threadCounts.clear(); |
| 52 | for (int i = 1; i < argc; i++) { |
| 53 | const std::string arg = argv[i]; |
| 54 | if (arg == "--help" || arg == "-h") { |
| 55 | usage(argv[0]); |
| 56 | std::exit(0); |
| 57 | } |
| 58 | if (arg == "--seconds" || arg == "-s") { |
| 59 | if (++i == argc) { |
| 60 | throw std::invalid_argument("--seconds requires a value"); |
| 61 | } |
| 62 | config.seconds = std::stod(argv[i]); |
| 63 | if (config.seconds <= 0.0) { |
| 64 | throw std::invalid_argument("--seconds must be greater than 0"); |
| 65 | } |
| 66 | continue; |
| 67 | } |
| 68 | if (arg == "--preserve-db") { |
| 69 | config.preserveDB = true; |
| 70 | continue; |
| 71 | } |
| 72 | const auto numThreads = std::stoull(arg); |
| 73 | if (numThreads == 0) { |
| 74 | throw std::invalid_argument("thread_count must be greater than 0"); |
| 75 | } |
| 76 | config.threadCounts.push_back(numThreads); |
| 77 | } |
| 78 | if (config.threadCounts.empty()) { |
| 79 | config.threadCounts = {1, 2, 4, 8}; |
| 80 | } |
| 81 | return config; |
| 82 | } |
| 83 | |
| 84 | struct CaseResult { |
| 85 | uint64_t totalWrites; |