Код: Выделить всё
int main() {
constexpr int n = 10'000'000;
vector timings;
int64_t result = 0;
timings.reserve(n+1);
for (int i = 0; i < n; i++) {
auto t0 = high_resolution_clock::now();
result += i;
auto t1 = high_resolution_clock::now();
timings.push_back(duration{t1-t0}.count());
}
sort(timings.begin(), timings.end());
println("\nmin: {:.3f}us med: {:.3f}us 99%: {:.3f}us max: {:.3f}us {}\n",
timings[0], timings[timings.size()/2], timings[99*timings.size()/100], timings.back(), result);
for (int i = timings.size()-9; i < timings.size(); i++)
println("{:.3f} ", timings[i]);
}
Код: Выделить всё
min: 0.020us med: 0.020us 99%: 0.030us max: 181.702us 49999995000000
104.366
107.432
138.891
140.454
142.368
143.409
145.293
150.453
181.702
Подробнее здесь: https://stackoverflow.com/questions/791 ... -benchmark
Мобильная версия