diff --git a/bench/Makefile b/bench/Makefile index 26c88ffe..1c777833 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -332,6 +332,7 @@ bench-string-step5: @./bench-string-2.exe 2000000 1 @./bench-string-2.exe 2000000 2 @./bench-string-2.exe 2000000 3 + @./bench-string-2.exe 2000000 4 bench-string-pgo: $(MAKE) bench-string XCFLAGS="-fprofile-generate=pgo" diff --git a/bench/bench-string-2.cpp b/bench/bench-string-2.cpp index 2da22f81..121382b4 100644 --- a/bench/bench-string-2.cpp +++ b/bench/bench-string-2.cpp @@ -27,9 +27,10 @@ #include #include -#include "m-string.h" #include "common.h" +#include "m-string.h" + #ifdef BENCH_CAN_USE_SDS extern "C" { #include "sds.h" @@ -40,6 +41,12 @@ extern "C" { #include "rapidstring.h" #endif +#ifdef BENCH_CAN_USE_BSTRLIB +#include "bstrlib.h" +#include "bstrwrap.h" +#include "bstraux.h" +#endif + /* * BENCH * 2000000 @@ -100,7 +107,7 @@ size_t bench_stl(unsigned n) return str.length(); } - + size_t bench_mlib(unsigned n) { string_t *tab = (string_t*) malloc (n * sizeof (string_t)); @@ -136,6 +143,43 @@ size_t bench_mlib(unsigned n) return length; } + +#ifdef BENCH_CAN_USE_BSTRLIB +size_t bench_bstrlib(unsigned n) +{ + vector tab; + tab.resize(n); + for(unsigned i = 0; i < n; i++) { + char tmp[10]; + sprintf(tmp, "%u", rand_get()); + tab[i] = tmp; + } + + CBString str; + for(unsigned i = 0; i < n; i++) { + str += tab[permutation_tab[i]]; + } + + size_t pos = 0; + do { + pos = str.find("1234", pos); + if (pos != string::npos) { + str.replace (pos, 4, "WELL"); + } + } while (pos != string::npos); + + pos = 0; + do { + pos = str.find("56789", pos); + if (pos != string::npos) { + str.replace (pos, 5, "DONE"); + } + } while (pos != string::npos); + + return str.length(); +} +#endif + #ifdef BENCH_CAN_USE_SDS sds SDS_replace_at(sds str, size_t pos, size_t len, const char str2[]) { @@ -276,6 +320,12 @@ int main(int argc, const char *argv[]) length = bench_rapidstring(n); name = "RAPID"; break; +#endif +#ifdef BENCH_CAN_USE_BSTRLIB + case 4: + length = bench_bstrlib(n); + name = "BSTRLIB"; + break; #endif default: exit(0); diff --git a/bench/bench-string.cpp b/bench/bench-string.cpp index 96ff4e12..5e678a73 100644 --- a/bench/bench-string.cpp +++ b/bench/bench-string.cpp @@ -36,7 +36,7 @@ */ /* Update of integrating M*LIB, LIBSRT, SDS, RAPIDSTRING & GLIB - done by Patrick Pelissier + Copyright (c) 2018-2019 Patrick Pelissier */ /*