From b011060458e9cd6a5f627960fe7bd73ff312f416 Mon Sep 17 00:00:00 2001 From: idealvin Date: Tue, 18 Jul 2023 23:09:27 +0800 Subject: [PATCH] add benchmark for fastring::find() --- test/str.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/str.cc b/test/str.cc index 2776520ad..cf754fe88 100644 --- a/test/str.cc +++ b/test/str.cc @@ -1,6 +1,10 @@ #include "co/fastring.h" #include "co/str.h" +#include "co/flag.h" #include "co/benchmark.h" +#include "co/cout.h" + +DEF_string(s, "", "string for search test"); BM_group(copy) { std::string ss; @@ -50,7 +54,27 @@ BM_group(copy) { BM_use(fs); } +BM_group(find) { + size_t p; + std::string s(FLG_s.data(), FLG_s.size()); + BM_add(std::string::find)( + p = s.find("xy"); + ) + BM_use(p); + co::print("p: ", p); + + BM_add(fastring::find)( + p = FLG_s.find("xy"); + ) + BM_use(p); + co::print("p: ", p); +} + int main(int argc, char** argv) { + flag::parse(argc, argv); + if (FLG_s.empty()) { + FLG_s.append(256, 'x').append(128, 'y').append(128, 'z'); + } bm::run_benchmarks(); return 0; }