Add BSTRLIB for MASTER STRING BENCHMARK

This commit is contained in:
Patrick Pelissier committed 2019-05-10 08:18:38 +02:00
1 parent edb4ccf63e
commit b2875f6ba0
3 files changed
+54 -3

No files matched your search

+52 -2
View File
@@ -27,9 +27,10 @@
#include <string>
#include <vector>
#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<CBString> 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);