| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
1 |
// A quick and dirty performance test. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
2 |
// For actual benchmarks see https://github.com/fmtlib/format-benchmark. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
3 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
4 |
#include <atomic> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
5 |
#include <chrono> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
6 |
#include <iterator> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
7 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
8 |
#include "fmt/format.h" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
9 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
10 |
int main() { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
11 |
const int n = 10000000; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
12 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
13 |
auto start = std::chrono::steady_clock::now(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
14 |
for (int iteration = 0; iteration < n; ++iteration) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
15 |
auto buf = fmt::memory_buffer(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
16 |
fmt::format_to(std::back_inserter(buf), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
17 |
"Hello, {}. The answer is {} and {}.", 1, 2345, 6789); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
18 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
19 |
std::atomic_signal_fence(std::memory_order_acq_rel); // Clobber memory. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
20 |
auto end = std::chrono::steady_clock::now(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
21 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
22 |
// Print time in milliseconds. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
23 |
std::chrono::duration<double> duration = end - start; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
24 |
fmt::print("{:.1f}\n", duration.count() * 1000); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
25 |
} |
|
|
1970-01-01 00:00 |
26 |
|