main.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Tencent is pleased to support the open source community by making wwsearch
  3. * available.
  4. *
  5. * Copyright (C) 2018-present Tencent. All Rights Reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  8. * use this file except in compliance with the License. You may obtain a copy of
  9. * the License at
  10. *
  11. * https://opensource.org/licenses/Apache-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OF ANY KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations under the License.
  17. */
  18. #include <stdlib.h>
  19. #include "include/search_util.h"
  20. #include "bench_db.h"
  21. #include "bench_index.h"
  22. #include "bench_merge.h"
  23. #include "bench_random.h"
  24. bool g_use_rocksdb = false;
  25. typedef void (*CasePtr)(wwsearch::ArgsHelper &args);
  26. typedef struct Case {
  27. CasePtr handler;
  28. std::string description;
  29. std::string usage;
  30. } Case;
  31. // do not use -c param.
  32. Case cases[] = {
  33. {.handler = wwsearch::BenchIndex::Run,
  34. .description = wwsearch::BenchIndex::Description,
  35. .usage = wwsearch::BenchIndex::Usage},
  36. {.handler = wwsearch::BenchMerge::Run,
  37. .description = wwsearch::BenchMerge::Description,
  38. .usage = wwsearch::BenchMerge::Usage},
  39. {.handler = wwsearch::BenchRandom::Run,
  40. .description = wwsearch::BenchRandom::Description,
  41. .usage = wwsearch::BenchRandom::Usage},
  42. {.handler = wwsearch::BenchDB::Run,
  43. .description = wwsearch::BenchDB::Description,
  44. .usage = wwsearch::BenchDB::Usage},
  45. };
  46. void ShowUsage(char **argv) {
  47. printf("Usage:\n");
  48. for (int i = 0; i < sizeof(cases) / sizeof(Case); i++) {
  49. printf("\t#%s \n\t -c %d %s\n\n", cases[i].description.c_str(), i + 1,
  50. cases[i].usage.c_str());
  51. }
  52. }
  53. int main(int argc, char **argv) {
  54. wwsearch::ArgsHelper helper(
  55. argc, argv, "a:d:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z:");
  56. int case_idx = helper.Int('c');
  57. if (helper.Int('r') == 1) {
  58. g_use_rocksdb = true;
  59. }
  60. if (sizeof(cases) / sizeof(Case) < case_idx || case_idx <= 0) {
  61. ShowUsage(argv);
  62. return -1;
  63. }
  64. cases[case_idx - 1].handler(helper);
  65. return 0;
  66. }