| 40 | } |
| 41 | |
| 42 | void BM_ParseTensorName(int iters, int arg) { |
| 43 | testing::StopTiming(); |
| 44 | random::PhiloxRandom philox(301, 17); |
| 45 | random::SimplePhilox rnd(&philox); |
| 46 | std::vector<string> names; |
| 47 | for (int i = 0; i < 100; i++) { |
| 48 | string name; |
| 49 | switch (arg) { |
| 50 | case 0: { // Generate random names |
| 51 | size_t len = Skewed(&rnd, 4); |
| 52 | while (name.size() < len) { |
| 53 | name += rnd.OneIn(4) ? '0' : 'a'; |
| 54 | } |
| 55 | if (rnd.OneIn(3)) { |
| 56 | strings::StrAppend(&name, ":", rnd.Uniform(12)); |
| 57 | } |
| 58 | break; |
| 59 | } |
| 60 | case 1: |
| 61 | name = "W1"; |
| 62 | break; |
| 63 | case 2: |
| 64 | name = "t0003"; |
| 65 | break; |
| 66 | case 3: |
| 67 | name = "weights"; |
| 68 | break; |
| 69 | case 4: |
| 70 | name = "weights:17"; |
| 71 | break; |
| 72 | case 5: |
| 73 | name = "^weights"; |
| 74 | break; |
| 75 | default: |
| 76 | LOG(FATAL) << "Unexpected arg"; |
| 77 | break; |
| 78 | } |
| 79 | names.push_back(name); |
| 80 | } |
| 81 | testing::StartTiming(); |
| 82 | TensorId id; |
| 83 | int index = 0; |
| 84 | int sum = 0; |
| 85 | while (--iters > 0) { |
| 86 | id = ParseTensorName(names[index++ % names.size()]); |
| 87 | sum += id.second; |
| 88 | } |
| 89 | VLOG(2) << sum; // Prevent compiler from eliminating loop body |
| 90 | } |
| 91 | BENCHMARK(BM_ParseTensorName)->Arg(0)->Arg(1)->Arg(2)->Arg(3)->Arg(4)->Arg(5); |
| 92 | |
| 93 | TEST(TensorIdTest, IsTensorIdControl) { |
nothing calls this directly
no test coverage detected