benchmark_name_gtest.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "benchmark/benchmark.h"
  2. #include "gtest/gtest.h"
  3. namespace {
  4. using namespace benchmark;
  5. using namespace benchmark::internal;
  6. TEST(BenchmarkNameTest, Empty) {
  7. const auto name = BenchmarkName();
  8. EXPECT_EQ(name.str(), std::string());
  9. }
  10. TEST(BenchmarkNameTest, FunctionName) {
  11. auto name = BenchmarkName();
  12. name.function_name = "function_name";
  13. EXPECT_EQ(name.str(), "function_name");
  14. }
  15. TEST(BenchmarkNameTest, FunctionNameAndArgs) {
  16. auto name = BenchmarkName();
  17. name.function_name = "function_name";
  18. name.args = "some_args:3/4/5";
  19. EXPECT_EQ(name.str(), "function_name/some_args:3/4/5");
  20. }
  21. TEST(BenchmarkNameTest, MinTime) {
  22. auto name = BenchmarkName();
  23. name.function_name = "function_name";
  24. name.args = "some_args:3/4";
  25. name.min_time = "min_time:3.4s";
  26. EXPECT_EQ(name.str(), "function_name/some_args:3/4/min_time:3.4s");
  27. }
  28. TEST(BenchmarkNameTest, MinWarmUpTime) {
  29. auto name = BenchmarkName();
  30. name.function_name = "function_name";
  31. name.args = "some_args:3/4";
  32. name.min_warmup_time = "min_warmup_time:3.5s";
  33. EXPECT_EQ(name.str(), "function_name/some_args:3/4/min_warmup_time:3.5s");
  34. }
  35. TEST(BenchmarkNameTest, Iterations) {
  36. auto name = BenchmarkName();
  37. name.function_name = "function_name";
  38. name.min_time = "min_time:3.4s";
  39. name.iterations = "iterations:42";
  40. EXPECT_EQ(name.str(), "function_name/min_time:3.4s/iterations:42");
  41. }
  42. TEST(BenchmarkNameTest, Repetitions) {
  43. auto name = BenchmarkName();
  44. name.function_name = "function_name";
  45. name.min_time = "min_time:3.4s";
  46. name.repetitions = "repetitions:24";
  47. EXPECT_EQ(name.str(), "function_name/min_time:3.4s/repetitions:24");
  48. }
  49. TEST(BenchmarkNameTest, TimeType) {
  50. auto name = BenchmarkName();
  51. name.function_name = "function_name";
  52. name.min_time = "min_time:3.4s";
  53. name.time_type = "hammer_time";
  54. EXPECT_EQ(name.str(), "function_name/min_time:3.4s/hammer_time");
  55. }
  56. TEST(BenchmarkNameTest, Threads) {
  57. auto name = BenchmarkName();
  58. name.function_name = "function_name";
  59. name.min_time = "min_time:3.4s";
  60. name.threads = "threads:256";
  61. EXPECT_EQ(name.str(), "function_name/min_time:3.4s/threads:256");
  62. }
  63. TEST(BenchmarkNameTest, TestEmptyFunctionName) {
  64. auto name = BenchmarkName();
  65. name.args = "first:3/second:4";
  66. name.threads = "threads:22";
  67. EXPECT_EQ(name.str(), "first:3/second:4/threads:22");
  68. }
  69. } // end namespace