fmt Version:
10.0.0
Benchmark:
#include <benchmark/benchmark.h>
#include <fmt/chrono.h>
#include <fmt/compile.h>
#include <fmt/core.h>
#include <fmt/format.h>
static void BM_format_to(benchmark::State &state) {
char out[1024] = {0};
auto format = FMT_COMPILE("{} - {} - {} - {} - {} - {} - {} - {} - {} - {}");
for (auto _ : state) {
fmt::format_to(out, format, "abcdef", 12345, "abcdef", 12345, "abcdef", 12345, "abcdef", 12345,
"abcdef", 12345);
}
}
BENCHMARK(BM_format_to);
static void BM_format_to_n(benchmark::State &state) {
char out[1024] = {0};
auto format = FMT_COMPILE("{} - {} - {} - {} - {} - {} - {} - {} - {} - {}");
for (auto _ : state) {
fmt::format_to_n(out, sizeof(out), format, "abcdef", 12345, "abcdef", 12345, "abcdef", 12345,
"abcdef", 12345, "abcdef", 12345);
}
}
BENCHMARK(BM_format_to_n);
BENCHMARK_MAIN();
Result:
Running ./benchmark_format_to.fmt10
Run on (16 X 2595.12 MHz CPU s)
CPU Caches:
L1 Data 32 KiB (x8)
L1 Instruction 32 KiB (x8)
L2 Unified 4096 KiB (x8)
L3 Unified 16384 KiB (x2)
Load Average: 1.17, 1.10, 1.59
---------------------------------------------------------
Benchmark Time CPU Iterations
---------------------------------------------------------
BM_format_to 78.3 ns 78.3 ns 8849844
BM_format_to_n 564 ns 564 ns 1242982
fmt Version:
10.0.0
Benchmark:
Result: