Skip to content

Commit

Permalink
add benchmark for fastring::find()
Browse files Browse the repository at this point in the history
  • Loading branch information
idealvin committed Jul 18, 2023
1 parent 6f055a8 commit b011060
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 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;
Expand Down Expand Up @@ -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;
}

0 comments on commit b011060

Please sign in to comment.