Update the benchmark to add more dependency in the computation to avoid

too agressive compiler optimisations.
This commit is contained in:
Patrick Pelissier committed 2017-08-03 21:28:42 +02:00
1 parent 2efe03f177
commit c7997fdd16
1 file changed
+126 -123
+126 -123
View File
@@ -105,168 +105,170 @@ int timeTest (double &res, int (*testfn) (int count), int count) {
#if defined (BENCH_CAN_USE_STL) #if defined (BENCH_CAN_USE_STL)
int testSTL_emptyCtor (int count) { int testSTL_emptyCtor (int count) {
int i, c = 0; int i, c = 0;
for (c=i=0; i < count; i++) { for (i=0; i < count; i++) {
std::string b; std::string b;
c += b.length (); c += b.length () ^ i;
} }
return c; return c;
} }
int testSTL_nonemptyCtor (int count) { int testSTL_nonemptyCtor (int count) {
int i, c = 0; int i, c = 0;
for (c=i=0; i < count; i++) { for (i=0; i < count; i++) {
std::string b (TESTSTRING1); std::string b (TESTSTRING1);
c += b.length (); c += b.length () ^ i;
} }
return c; return c;
} }
int testSTL_cstrAssignment (int count) { int testSTL_cstrAssignment (int count) {
int i, c = 0; int i, c = 0;
std::string b; std::string b;
for (c=i=0; i < count; i++) { for (i=0; i < count; i++) {
b = TESTSTRING1; b = TESTSTRING1;
c += b.length (); c += b.length () ^ i;
} }
return c; return c;
} }
int testSTL_extraction (int count) { int testSTL_extraction (int count) {
int i, c = 0; int i, c = 0;
std::string b (TESTSTRING1); std::string b (TESTSTRING1);
for (c=i=0; i < count; i++) { for (i=0; i < count; i++) {
c += b[(i & 7)]; c += b[(i & 7)];
c += b[(i & 7) ^ 8]; c += b[(i & 7) ^ 8];
c += b.c_str()[(i & 7) ^ 4]; c += b.c_str()[(i & 7) ^ 4] ^ i;
} }
return c; return c;
} }
int testSTL_scan (int count) { int testSTL_scan (int count) {
int i, c = 0; int i, c = 0;
std::string b ("Dot. 123. Some more data."); std::string b ("Dot. 123. Some more data.");
for (c=i=0; i < count; i++) { for (i=0; i < count; i++) {
c += b.find ('.'); c += b.find ('.');
c += b.find ("123"); c += b.find ("123");
c += b.find_first_of ("sm"); c += b.find_first_of ("sm") ^i;
} }
return c; return c;
} }
int testSTL_concat (int count) { int testSTL_concat (int count) {
int i, j, c = 0; int i, j, c = 0;
std::string a (TESTSTRING1); std::string a (TESTSTRING1);
std::string accum; std::string accum;
for (j=0; j < count; j++) { for (j=0; j < count; j++) {
accum = ""; accum = "";
for (i=0; i < 250; i++) { for (i=0; i < 250; i++) {
accum += a; accum += a;
accum += "!!"; accum += "!!";
} c += accum.length() ^i;
} }
return c; }
return c;
} }
int testSTL_replace (int count) { int testSTL_replace (int count) {
int j, c = 0; int j, c = 0;
std::string a (TESTSTRING1); std::string a (TESTSTRING1);
for (j=0; j < count; j++) { for (j=0; j < count; j++) {
a.replace (11, 4, "XXXXXX"); a.replace (11, 4, "XXXXXX");
a.replace (23, 2, "XXXXXX"); a.replace (23, 2, "XXXXXX");
a.replace ( 4, 8, "XX"); a.replace ( 4, 8, "XX");
c += a.length (); c += a.length () ^ j;
} }
return c; return c;
} }
#endif #endif
#ifdef BENCH_CAN_USE_BSTRLIB #ifdef BENCH_CAN_USE_BSTRLIB
int testCBS_emptyCtor (int count) { int testCBS_emptyCtor (int count) {
int i, c = 0; int i, c = 0;
for (c=i=0; i < count; i++) { for (i=0; i < count; i++) {
CBString b; CBString b;
c += b.length (); c += b.length ()^i;
} }
return c; return c;
} }
int testCBS_nonemptyCtor (int count) { int testCBS_nonemptyCtor (int count) {
int i, c = 0; int i, c = 0;
for (c=i=0; i < count; i++) { for (i=0; i < count; i++) {
CBString b (TESTSTRING1); CBString b (TESTSTRING1);
c += b.length (); c += b.length () ^i;
} }
return c; return c;
} }
int testCBS_cstrAssignment (int count) { int testCBS_cstrAssignment (int count) {
int i, c = 0; int i, c = 0;
CBString b; CBString b;
for (c=i=0; i < count; i++) { for (i=0; i < count; i++) {
b = TESTSTRING1; b = TESTSTRING1;
c += b.length (); c += b.length () ^i;
} }
return c; return c;
} }
int testCBS_extraction (int count) { int testCBS_extraction (int count) {
int i, c = 0; int i, c = 0;
CBString b (TESTSTRING1); CBString b (TESTSTRING1);
for (c=i=0; i < count; i++) { for (i=0; i < count; i++) {
c += b[(i & 7)]; c += b[(i & 7)];
c += b[(i & 7) ^ 8]; c += b[(i & 7) ^ 8];
c += ((const char *)b)[(i & 7) ^ 4]; c += ((const char *)b)[(i & 7) ^ 4] ^i;
} }
return c; return c;
} }
int testCBS_scan (int count) { int testCBS_scan (int count) {
int i, c = 0; int i, c = 0;
CBString b ("Dot. 123. Some more data."); CBString b ("Dot. 123. Some more data.");
for (c=i=0; i < count; i++) { for (c=i=0; i < count; i++) {
c += b.find ('.'); c += b.find ('.');
c += b.find ("123"); c += b.find ("123");
c += b.findchr ("sm"); c += b.findchr ("sm") ^i;
} }
return c; return c;
} }
int testCBS_concat (int count) { int testCBS_concat (int count) {
int i, j, c = 0; int i, j, c = 0;
CBString a (TESTSTRING1); CBString a (TESTSTRING1);
CBString accum; CBString accum;
for (j=0; j < count; j++) { for (j=0; j < count; j++) {
accum = ""; accum = "";
for (i=0; i < 250; i++) { for (i=0; i < 250; i++) {
accum += a; accum += a;
accum += "!!"; accum += "!!";
} c+= accum.length() ^i;
} }
return c; }
return c;
} }
int testCBS_replace (int count) { int testCBS_replace (int count) {
int j, c = 0; int j, c = 0;
CBString a (TESTSTRING1); CBString a (TESTSTRING1);
for (j=0; j < count; j++) { for (j=0; j < count; j++) {
a.replace (11, 4, "XXXXXX"); a.replace (11, 4, "XXXXXX");
a.replace (23, 2, "XXXXXX"); a.replace (23, 2, "XXXXXX");
a.replace ( 4, 8, "XX"); a.replace ( 4, 8, "XX");
c += a.length (); c += a.length () ^j;
} }
return c; return c;
} }
#endif #endif
@@ -276,7 +278,7 @@ int testMLIB_emptyCtor (int count) {
for (c=i=0; i < count; i++) { for (c=i=0; i < count; i++) {
string_t b; string_t b;
string_init(b); string_init(b);
c += string_get_length(b); c += string_get_length(b) ^i;
string_clear(b); string_clear(b);
} }
return c; return c;
@@ -287,7 +289,7 @@ int testMLIB_nonemptyCtor (int count) {
for (c=i=0; i < count; i++) { for (c=i=0; i < count; i++) {
string_t b; string_t b;
string_init_set_str(b, TESTSTRING1); string_init_set_str(b, TESTSTRING1);
c += string_get_length(b); c += string_get_length(b) ^i;
string_clear(b); string_clear(b);
} }
return c; return c;
@@ -299,7 +301,7 @@ int testMLIB_cstrAssignment (int count) {
string_init(b); string_init(b);
for (c=i=0; i < count; i++) { for (c=i=0; i < count; i++) {
string_set_str(b, TESTSTRING1); string_set_str(b, TESTSTRING1);
c += string_get_length(b); c += string_get_length(b) ^i;
} }
string_clear(b); string_clear(b);
return c; return c;
@@ -314,7 +316,7 @@ int testMLIB_extraction (int count) {
for (c=i=0; i < count; i++) { for (c=i=0; i < count; i++) {
c += string_get_char(b, (i & 7)); c += string_get_char(b, (i & 7));
c += string_get_char(b, (i & 7) ^ 8); c += string_get_char(b, (i & 7) ^ 8);
c += string_get_char(b, (i & 7) ^ 4); c += string_get_char(b, (i & 7) ^ 4) ^i;
} }
string_clear(b); string_clear(b);
return c; return c;
@@ -328,7 +330,7 @@ int testMLIB_scan (int count) {
for (c=i=0; i < count; i++) { for (c=i=0; i < count; i++) {
c += string_search_char (b, '.'); c += string_search_char (b, '.');
c += string_search_str (b, "123"); c += string_search_str (b, "123");
c += string_pbrk (b, "sm"); c += string_pbrk (b, "sm") ^i;
} }
string_clear(b); string_clear(b);
return c; return c;
@@ -346,6 +348,7 @@ int testMLIB_concat (int count) {
for (i=0; i < 250; i++) { for (i=0; i < 250; i++) {
string_cat(accum, a); string_cat(accum, a);
string_cat_str(accum, "!!"); string_cat_str(accum, "!!");
c += string_get_length(accum) ^i;
} }
} }
string_clear(a); string_clear(a);
@@ -362,7 +365,7 @@ int testMLIB_replace (int count) {
string_replace_at(a, 11, 4, "XXXXXX"); string_replace_at(a, 11, 4, "XXXXXX");
string_replace_at(a, 23, 2, "XXXXXX"); string_replace_at(a, 23, 2, "XXXXXX");
string_replace_at(a, 4, 8, "XX"); string_replace_at(a, 4, 8, "XX");
c += string_get_length(a); c += string_get_length(a) ^j;
} }
string_clear(a); string_clear(a);