代码拉取完成,页面将自动刷新
#include <benchmark/benchmark.h>
#include <absl/strings/str_split.h>
#include <absl/strings/numbers.h>
#include <boost/regex.hpp>
#include <boost/algorithm/string/regex.hpp>
#include <boost/algorithm/string.hpp>
#include <Corrade/Utility/String.h>
#include <array>
#include <charconv>
const std::string S_PI("3.141592657");
// string to number
void s2num_abseil() {
double pi;
absl::SimpleAtod(S_PI, &pi);
}
void s2num_fromchar() {
double pi;
std::from_chars(S_PI.data(), S_PI.data() + S_PI.size(), pi);
}
std::vector<std::string> split_move(const std::string& string, const char delimiter) {
std::vector<std::string> parts;
std::size_t oldpos = 0, pos = std::string::npos;
while((pos = string.find(delimiter, oldpos)) != std::string::npos) {
parts.emplace_back((string.substr(oldpos, pos - oldpos)));
oldpos = pos + 1;
}
if(!string.empty())
parts.emplace_back((string.substr(oldpos)));
return parts;
}
void split_absl() {
std::string text("asfasdfas asf asdf s asdf asdf asdf fdfd fda");
std::vector<std::string> substrs = absl::StrSplit(text, ' ');
}
void split_boost() {
std::string text("asfasdfas asf asdf s asdf asdf asdf fdfd fda");
std::vector<std::string> substrs;
boost::split(substrs, text, boost::is_any_of(" "));
}
void split_corrade() {
std::string text("asfasdfas asf asdf s asdf asdf asdf fdfd fda");
std::vector<std::string> substrs = Corrade::Utility::String::splitWithoutEmptyParts(text, ' ');
}
void split_corrade_move() {
std::string text("asfasdfas asf asdf s asdf asdf asdf fdfd fda");
std::vector<std::string> substrs = split_move(text, ' ');
}
static void BM_absl(benchmark::State& state) {
for (auto _ : state) {
split_absl();
}
}
static void BM_boost(benchmark::State& state) {
for(auto _ : state) {
split_boost();
}
}
static void BM_corrade(benchmark::State& state) {
for(auto _ : state) {
split_corrade();
}
}
static void BM_corrade_move(benchmark::State& state) {
for(auto _ : state) {
split_corrade_move();
}
}
//
static void BM_s2m_abseil(benchmark::State& state) {
for(auto _ : state) {
s2num_abseil();
}
}
static void BM_s2m_fromchar(benchmark::State& state) {
for(auto _ : state) {
s2num_fromchar();
}
}
BENCHMARK(BM_absl);
BENCHMARK(BM_boost);
BENCHMARK(BM_corrade);
BENCHMARK(BM_corrade_move);
BENCHMARK(BM_s2m_abseil);
BENCHMARK(BM_s2m_fromchar);
BENCHMARK_MAIN();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。