mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
117 lines
2.7 KiB
C++
117 lines
2.7 KiB
C++
#include <tuple>
|
|
|
|
#include "benchmark/benchmark.h"
|
|
|
|
#include "fmt/format.h"
|
|
#include "fmt/chrono.h"
|
|
|
|
#include "libimp/fmt.h"
|
|
|
|
namespace {
|
|
|
|
void imp_fmt_string(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = imp::fmt("hello world.hello world.hello world.hello world.hello world.");
|
|
}
|
|
}
|
|
|
|
void imp_multi_fmt_string(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = imp::fmt("hello world.", "hello world.", "hello world.", "hello world.", "hello world.");
|
|
}
|
|
}
|
|
|
|
void fmt_fmt_string(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = fmt::format("hello world.hello world.hello world.hello world.hello world.");
|
|
}
|
|
}
|
|
|
|
void fmt_multi_fmt_string(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = fmt::format("{}{}{}{}{}",
|
|
"hello world.", " hello world.", " hello world.", " hello world.", " hello world.");
|
|
}
|
|
}
|
|
|
|
void imp_fmt_int(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = imp::fmt(654321);
|
|
}
|
|
}
|
|
|
|
void imp_multi_fmt_int(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = imp::fmt(654321, 654321, 654321, 654321, 654321);
|
|
}
|
|
}
|
|
|
|
void fmt_fmt_int(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = fmt::format("{}", 654321);
|
|
}
|
|
}
|
|
|
|
void fmt_multi_fmt_int(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = fmt::format("{}{}{}{}{}", 654321, 654321, 654321, 654321, 654321);
|
|
}
|
|
}
|
|
|
|
void imp_fmt_float(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = imp::fmt(654.321);
|
|
}
|
|
}
|
|
|
|
void imp_multi_fmt_float(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = imp::fmt(654.321, 654.321, 654.321, 654.321, 654.321);
|
|
}
|
|
}
|
|
|
|
void fmt_fmt_float(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = fmt::format("{}", 654.321);
|
|
}
|
|
}
|
|
|
|
void fmt_multi_fmt_float(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
std::ignore = fmt::format("{}{}{}{}{}", 654.321, 654.321, 654.321, 654.321, 654.321);
|
|
}
|
|
}
|
|
|
|
void imp_fmt_chrono(benchmark::State &state) {
|
|
auto now = std::chrono::system_clock::now();
|
|
for (auto _ : state) {
|
|
std::ignore = imp::fmt(now);
|
|
}
|
|
}
|
|
|
|
void fmt_fmt_chrono(benchmark::State &state) {
|
|
auto now = std::chrono::system_clock::now();
|
|
for (auto _ : state) {
|
|
std::ignore = fmt::format("{}", now);
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
BENCHMARK(imp_fmt_string);
|
|
BENCHMARK(fmt_fmt_string);
|
|
BENCHMARK(imp_fmt_int);
|
|
BENCHMARK(fmt_fmt_int);
|
|
BENCHMARK(imp_fmt_float);
|
|
BENCHMARK(fmt_fmt_float);
|
|
|
|
BENCHMARK(imp_multi_fmt_string);
|
|
BENCHMARK(fmt_multi_fmt_string);
|
|
BENCHMARK(imp_multi_fmt_int);
|
|
BENCHMARK(fmt_multi_fmt_int);
|
|
BENCHMARK(imp_multi_fmt_float);
|
|
BENCHMARK(fmt_multi_fmt_float);
|
|
|
|
BENCHMARK(imp_fmt_chrono);
|
|
BENCHMARK(fmt_fmt_chrono);
|