Created
June 4, 2022 20:59
-
-
Save ifarbod/c949c9b60224ec3bc403bd92421369f6 to your computer and use it in GitHub Desktop.
Benchmark std::format vs fmt::format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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