Skip to content

Instantly share code, notes, and snippets.

@ifarbod
Created June 4, 2022 20:59
Show Gist options
  • Save ifarbod/c949c9b60224ec3bc403bd92421369f6 to your computer and use it in GitHub Desktop.
Save ifarbod/c949c9b60224ec3bc403bd92421369f6 to your computer and use it in GitHub Desktop.
Benchmark std::format vs fmt::format
// Copyright (c) 2018-2022 iFarbod and other contributors. All Rights Reserved.
//
// SPDX-License-Identifier: MIT
#include <format>
#include <vendor/benchmark/include/benchmark/benchmark.h>
#define FMT_USE_FULL_CACHE_DRAGONBOX 1
#include <vendor/fmt/include/fmt/format.h>
void fmt_format_runtime(benchmark::State& state)
{
for (auto _ : state)
{
std::string s{fmt::format("{}", 1'000'000)};
benchmark::DoNotOptimize(s);
}
}
BENCHMARK(fmt_format_runtime);
void std_format_runtime(benchmark::State& state)
{
for (auto _ : state)
{
std::string s{std::format("{}", 1'000'000)};
benchmark::DoNotOptimize(s);
}
}
BENCHMARK(std_format_runtime);
BENCHMARK_MAIN();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment