Add GLIB to string bench
This commit is contained in:
1 parent
0d641f0d17
commit
0ef051e6d2
2 files changed
+147
-9
No files matched your search
+10
-7
@@ -301,17 +301,20 @@ bench-maxdict:
|
||||
# BSTRLIB shall point to the BSTRLIB sources
|
||||
# LIBSRT shall point to the LIBSRT sources
|
||||
bench-string:
|
||||
@if test -n "$${BSTRLIB}" ; then $(MAKE) bench-string-with BENCH_DEF="-DBENCH_CAN_USE_BSTRLIB -I ${BSTRLIB} $${BSTRLIB}/obj/bstrlib.o $${BSTRLIB}/obj/bstraux.o $${BSTRLIB}/obj/bstrwrap.o" ; else $(MAKE) bench-string-with ; fi
|
||||
@if test -n "$${BSTRLIB}" ; then $(MAKE) bench-string-step1 BENCH_DEF="-DBENCH_CAN_USE_BSTRLIB -I ${BSTRLIB} $${BSTRLIB}/obj/bstrlib.o $${BSTRLIB}/obj/bstraux.o $${BSTRLIB}/obj/bstrwrap.o" ; else $(MAKE) bench-string-step1 ; fi
|
||||
|
||||
bench-string-with:
|
||||
@if test -n "$${LIBSRT}" ; then $(MAKE) bench-string-with2 BENCH_DEF="$(BENCH_DEF) -DBENCH_CAN_USE_LIBSRT -I$${LIBSRT}/src $${LIBSRT}/libsrt.a" ; else $(MAKE) bench-string-with2 BENCH_DEF="$(BENCH_DEF)"; fi
|
||||
bench-string-step1:
|
||||
@if test -n "$${LIBSRT}" ; then $(MAKE) bench-string-step2 BENCH_DEF="$(BENCH_DEF) -DBENCH_CAN_USE_LIBSRT -I$${LIBSRT}/src $${LIBSRT}/libsrt.a" ; else $(MAKE) bench-string-step2 BENCH_DEF="$(BENCH_DEF)"; fi
|
||||
|
||||
#NOTE: Need to build by hand sds.o since it is not build by default and sds.c is not compatible with C++
|
||||
bench-string-with2:
|
||||
@if test -n "$${SDS}" ; then $(MAKE) bench-string-with3 BENCH_DEF="$(BENCH_DEF) -fpermissive -DBENCH_CAN_USE_SDS -I$${SDS}/ $${SDS}/sds.o" ; else $(MAKE) bench-string-with3 BENCH_DEF="$(BENCH_DEF)"; fi
|
||||
bench-string-step2:
|
||||
@if test -n "$${SDS}" ; then $(MAKE) bench-string-step3 BENCH_DEF="$(BENCH_DEF) -fpermissive -DBENCH_CAN_USE_SDS -I$${SDS}/ $${SDS}/sds.o" ; else $(MAKE) bench-string-step3 BENCH_DEF="$(BENCH_DEF)"; fi
|
||||
|
||||
bench-string-with3:
|
||||
@if test -n "$${RAPIDSTRING}" ; then $(MAKE) bench-string-exe BENCH_DEF="$(BENCH_DEF) -DBENCH_CAN_USE_RAPIDSTRING -I$${RAPIDSTRING}/ " ; else $(MAKE) bench-string-exe BENCH_DEF="$(BENCH_DEF)"; fi
|
||||
bench-string-step3:
|
||||
@if test -n "$${RAPIDSTRING}" ; then $(MAKE) bench-string-step4 BENCH_DEF="$(BENCH_DEF) -DBENCH_CAN_USE_RAPIDSTRING -I$${RAPIDSTRING}/ " ; else $(MAKE) bench-string-step4 BENCH_DEF="$(BENCH_DEF)"; fi
|
||||
|
||||
bench-string-step4:
|
||||
@if test -n "$${GLIB}" ; then $(MAKE) bench-string-exe BENCH_DEF="$(BENCH_DEF) -DBENCH_CAN_USE_GLIB $$(pkg-config --cflags --libs glib-2.0)" ; else $(MAKE) bench-string-exe BENCH_DEF="$(BENCH_DEF)"; fi
|
||||
|
||||
bench-string-exe:
|
||||
$(CXX) $(CFLAGS) $(CPPFLAGS) -I "$${BSTRLIB}" -DBENCH_CAN_USE_STL -DBENCH_CAN_USE_MSTARLIB bench-string.cpp common.c -o bench-string.exe $(BENCH_DEF)
|
||||
|
||||
+137
-2
@@ -35,8 +35,9 @@
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* Update of integrating M*LIB, LIBSRT, SDS & RAPIDSTRING
|
||||
done by Patrick Pelissier */
|
||||
/* Update of integrating M*LIB, LIBSRT, SDS, RAPIDSTRING & GLIB
|
||||
done by Patrick Pelissier
|
||||
*/
|
||||
|
||||
/*
|
||||
* Benchmark based on the features tested by benchmark seen here:
|
||||
@@ -82,6 +83,11 @@ extern "C" {
|
||||
#include "rapidstring.h"
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(BENCH_CAN_USE_GLIB)
|
||||
#include "gmodule.h"
|
||||
#endif
|
||||
|
||||
/* Time of a test */
|
||||
#define TEST_SECONDS (5)
|
||||
|
||||
@@ -89,6 +95,7 @@ extern "C" {
|
||||
* This macro puts a memory barrier and prevents the optimizer from
|
||||
* optimizing too much the inline functions and literraly breaking
|
||||
* the benchmark by doing nothing.
|
||||
* Better than nothing, but far from perfect.
|
||||
*/
|
||||
#define BARRIER(addr) compiler_barrier((void*) addr)
|
||||
|
||||
@@ -742,6 +749,103 @@ int testRAPIDSTRING_concat (int count) {
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BENCH_CAN_USE_GLIB
|
||||
int testGLIB_emptyCtor (int count) {
|
||||
int i, c = 0;
|
||||
for (c=i=0; i < count; i++) {
|
||||
GString *b = g_string_new("");
|
||||
BARRIER(b);
|
||||
c += b->len;
|
||||
g_string_free(b, TRUE);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int testGLIB_nonemptyCtor (int count) {
|
||||
int i, c = 0;
|
||||
for (c=i=0; i < count; i++) {
|
||||
GString *b = g_string_new(TESTSTRING1);
|
||||
BARRIER(b);
|
||||
c += b->len;
|
||||
g_string_free(b, TRUE);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int testGLIB_smallnonemptyCtor (int count) {
|
||||
int i, c = 0;
|
||||
for (c=i=0; i < count; i++) {
|
||||
GString *b = g_string_new(SMALLTESTSTRING1);
|
||||
BARRIER(b);
|
||||
c += b->len;
|
||||
g_string_free(b, TRUE);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int testGLIB_cstrAssignment (int count) {
|
||||
int i, c = 0;
|
||||
GString *b = g_string_new("");
|
||||
for (c=i=0; i < count; i++) {
|
||||
b = g_string_assign(b, TESTSTRING1);
|
||||
BARRIER(b);
|
||||
c += b->len ^i;
|
||||
}
|
||||
g_string_free(b, TRUE);
|
||||
return c;
|
||||
}
|
||||
|
||||
int testGLIB_extraction (int count) {
|
||||
int i, c = 0;
|
||||
GString *b = g_string_new(TESTSTRING1);
|
||||
for (c=i=0; i < count; i++) {
|
||||
c += b->str[(i & 7)];
|
||||
c += b->str[(i & 7) ^ 8];
|
||||
c += b->str[(i & 7) ^ 4] ^i;
|
||||
BARRIER(b);
|
||||
}
|
||||
g_string_free(b, TRUE);
|
||||
return c;
|
||||
}
|
||||
|
||||
int testGLIB_scan (int count) {
|
||||
int i, c = 0;
|
||||
GString *b = g_string_new("Dot. 123. Some more data.");
|
||||
|
||||
for (c=i=0; i < count; i++) {
|
||||
c += (strchr(b->str, '.')-b->str);
|
||||
c += (strstr (b->str, "123")-b->str);
|
||||
c += (strpbrk (b->str, "sm")-b->str) ^i;
|
||||
BARRIER(b);
|
||||
}
|
||||
g_string_free(b, TRUE);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
int testGLIB_concat (int count) {
|
||||
int i, j, c = 0;
|
||||
GString *a = g_string_new(TESTSTRING1);
|
||||
GString *accum = g_string_new("");
|
||||
|
||||
for (j=0; j < count; j++) {
|
||||
accum = g_string_assign(accum, "");
|
||||
for (i=0; i < 250; i++) {
|
||||
accum = g_string_append(accum, a->str);
|
||||
accum = g_string_append(accum, "!!");
|
||||
BARRIER(accum);
|
||||
c += accum->len ^i;
|
||||
}
|
||||
}
|
||||
g_string_free(a, TRUE);
|
||||
g_string_free(accum, TRUE);
|
||||
return c;
|
||||
}
|
||||
|
||||
//int testGLIB_replace (int count): not available
|
||||
#endif
|
||||
|
||||
|
||||
#define NTESTS 8
|
||||
struct flags {
|
||||
int runtest[NTESTS];
|
||||
@@ -958,6 +1062,37 @@ int benchTest (const struct flags * runflags) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BENCH_CAN_USE_GLIB
|
||||
if (runflags->runtest[0]) {
|
||||
c += timeTest (cps, testGLIB_emptyCtor, 100000);
|
||||
print ("GLIB", "empty constructor", cps);
|
||||
}
|
||||
if (runflags->runtest[1]) {
|
||||
c += timeTest (cps, testGLIB_nonemptyCtor, 100000);
|
||||
print ("GLIB", "non-empty constructor", cps);
|
||||
}
|
||||
if (runflags->runtest[2]) {
|
||||
c += timeTest (cps, testGLIB_smallnonemptyCtor, 100000);
|
||||
print ("GLIB", "small non-empty constructor", cps);
|
||||
}
|
||||
if (runflags->runtest[3]) {
|
||||
c += timeTest (cps, testGLIB_cstrAssignment, 100000);
|
||||
print ("GLIB", "Char * assignment", cps);
|
||||
}
|
||||
if (runflags->runtest[4]) {
|
||||
c += timeTest (cps, testGLIB_extraction, 100000);
|
||||
print ("GLIB", "char extraction", cps);
|
||||
}
|
||||
if (runflags->runtest[5]) {
|
||||
c += timeTest (cps, testGLIB_scan, 100000);
|
||||
print ("GLIB", "scan", cps);
|
||||
}
|
||||
if (runflags->runtest[6]) {
|
||||
c += timeTest (cps, testGLIB_concat, 10);
|
||||
print ("GLIB", "concatenation", cps * 250);
|
||||
}
|
||||
#endif
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user