| 97 | } |
| 98 | |
| 99 | void RunBench(Benchmark* b, int nthread, int siz) { |
| 100 | int n, last; |
| 101 | |
| 102 | // TODO(yeshunping): support Threaded benchmarks. |
| 103 | if (nthread != 1) { |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | // run once in case it's expensive |
| 108 | n = 1; |
| 109 | runN(b, n, siz); |
| 110 | while (used_time_ns < static_cast<int>(1e9) && |
| 111 | n < static_cast<int>(1e9)) { |
| 112 | last = n; |
| 113 | if (used_time_ns / n == 0) { |
| 114 | n = 1e9; |
| 115 | } else { |
| 116 | n = 1e9 / (used_time_ns / n); |
| 117 | } |
| 118 | n = std::max(last + 1, std::min(n + n / 2, 100 * last)); |
| 119 | n = round(n); |
| 120 | runN(b, n, siz); |
| 121 | } |
| 122 | |
| 123 | char mb[100]; |
| 124 | char suf[100]; |
| 125 | mb[0] = '\0'; |
| 126 | suf[0] = '\0'; |
| 127 | if (used_time_ns > 0 && processed_bytes > 0) { |
| 128 | snprintf(mb, sizeof mb, "\t%7.2f MB/s", |
| 129 | (static_cast<double>(processed_bytes) / 1e6) / |
| 130 | (static_cast<double>(used_time_ns) / 1e9)); |
| 131 | } |
| 132 | if (b->fnr || b->lo != b->hi) { |
| 133 | if (siz >= (1 << 20)) { |
| 134 | snprintf(suf, sizeof suf, "/%dM", siz / (1 << 20)); |
| 135 | } else if (siz >= (1 << 10)) { |
| 136 | snprintf(suf, sizeof suf, "/%dK", siz / (1 << 10)); |
| 137 | } else { |
| 138 | snprintf(suf, sizeof suf, "/%d", siz); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | printf("%s%s%s%s\t%s%8lld\t%s%10lld ns/op%s%s%s\n", |
| 143 | kColorCyan, b->name, |
| 144 | kColorPurple, suf, |
| 145 | kColorBlue, (long long) n, // NOLINT |
| 146 | kColorYellow, (long long) used_time_ns / n, // NOLINT |
| 147 | kColorGreen, mb, |
| 148 | kColorEnd); |
| 149 | fflush(stdout); |
| 150 | } |
| 151 | } // namespace toft |