diff --git a/bench/Makefile b/bench/Makefile index 812b513b..4c1b1f73 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -12,6 +12,7 @@ bench-mlib: @./bench-mlib.exe 3 @./bench-mlib.exe 4 @./bench-mlib.exe 6 + @./bench-mlib.exe 7 bench-stl: $(CXX) $(CFLAGS) $(CPPFLAGS) bench-stl.cpp -o bench-stl.exe @@ -21,6 +22,7 @@ bench-stl: @./bench-stl.exe 4 @./bench-stl.exe 5 @./bench-stl.exe 6 + @./bench-stl.exe 7 bench-qt: $(CXX) $(CFLAGS) $(CPPFLAGS) -fPIC $$(pkg-config --libs --cflags Qt5Core) bench-qt.cpp -o bench-qt.exe @@ -30,6 +32,7 @@ bench-qt: @./bench-qt.exe 4 @./bench-qt.exe 5 @./bench-qt.exe 6 + @./bench-qt.exe 7 bench-klib: $(CC) $(CFLAGS) $(CPPFLAGS) $${KLIB_CPPFLAGS} bench-klib.c -o bench-klib.exe @@ -38,6 +41,7 @@ bench-klib: @./bench-klib.exe 3 @./bench-klib.exe 4 @./bench-klib.exe 6 + @./bench-klib.exe 7 bench-glib: $(CC) $(CFLAGS) $(CPPFLAGS) $$(pkg-config --libs --cflags glib-2.0) bench-glib.c -o bench-glib.exe @@ -46,6 +50,7 @@ bench-glib: @./bench-glib.exe 3 @./bench-glib.exe 4 @./bench-glib.exe 6 + @./bench-glib.exe 7 clean: rm -f *.o bench-*.exe *~ diff --git a/bench/bench-glib.c b/bench/bench-glib.c index 1199d796..6302c8f1 100644 --- a/bench/bench-glib.c +++ b/bench/bench-glib.c @@ -200,6 +200,28 @@ test_dict_big(unsigned long n) /********************************************************************************************/ +static gint cmp_float(gconstpointer a, + gconstpointer b) +{ + const float *pa = a, *pb = b; + return (*pa < *pb) ? -1 : (*pa > *pb); +} + +static void test_sort(size_t n) +{ + rand_init(); + GArray *a1 = g_array_new (FALSE, FALSE, sizeof (float)); + for(size_t i = 0; i < n; i++) { + float v = rand_get(); + g_array_append_val(a1, v ); + } + g_array_sort(a1, cmp_float); + g_result = g_array_index (a1, float, 0); + g_array_free(a1, FALSE); +} + +/********************************************************************************************/ + int main(int argc, const char *argv[]) { int n = (argc > 1) ? atoi(argv[1]) : 0; @@ -213,5 +235,6 @@ int main(int argc, const char *argv[]) test_function("Dict time", 1000000, test_dict); if (n == 6) test_function("DictB time", 1000000, test_dict_big); + if (n == 7) + test_function("Sort time", 10000000, test_sort); } - diff --git a/bench/bench-klib.c b/bench/bench-klib.c index b90d5b31..7da038d0 100644 --- a/bench/bench-klib.c +++ b/bench/bench-klib.c @@ -11,6 +11,7 @@ #include "klist.h" #include "kbtree.h" #include "khash.h" +#include "ksort.h" unsigned long g_result; @@ -197,6 +198,27 @@ test_dict_big(unsigned long n) kh_destroy(iub, dict); } +/********************************************************************************************/ +// NOTE: Needed for compiling +static double drand48(void) { return rand_get(); } + +KSORT_INIT_GENERIC(float) + +static void test_sort(size_t n) +{ + rand_init(); + kvec_t(float) a1; + + kv_init(a1); + for(size_t i = 0; i < n; i++) { + kv_push(float, a1, rand_get() ); + } + // NOTE: Is-it the right way to do? Seems very low level! + ks_introsort_float(n, & kv_A(a1, 0)); + g_result = kv_A(a1, 0); + kv_destroy(a1); +} + /********************************************************************************************/ int main(int argc, const char *argv[]) @@ -212,5 +234,7 @@ int main(int argc, const char *argv[]) test_function("Dict time", 1000000, test_dict); if (n == 6) test_function("DictB time", 1000000, test_dict_big); + if (n == 7) + test_function("Sort time", 10000000, test_sort); } diff --git a/bench/bench-mlib.c b/bench/bench-mlib.c index 04559d8f..cac33807 100644 --- a/bench/bench-mlib.c +++ b/bench/bench-mlib.c @@ -11,6 +11,7 @@ #include "m-list.h" #include "m-rbtree.h" #include "m-dict.h" +#include "m-algo.h" unsigned long g_result; @@ -173,6 +174,23 @@ test_dict_big(unsigned long n) /********************************************************************************************/ +ARRAY_DEF(float, float) +ALGO_DEF(afloat, ARRAY_OPLIST(float)) + +static void test_sort(size_t n) +{ + rand_init(); + M_LET(a1, ARRAY_OPLIST(float)) { + for(size_t i = 0; i < n; i++) { + array_float_push_back(a1, rand_get() ); + } + afloat_sort(a1); + g_result = *array_float_get(a1, 0); + } +} + +/********************************************************************************************/ + int main(int argc, const char *argv[]) { int n = (argc > 1) ? atoi(argv[1]) : 0; @@ -186,5 +204,7 @@ int main(int argc, const char *argv[]) test_function("Dict time", 1000000, test_dict); if (n == 6) test_function("DictB time", 1000000, test_dict_big); + if (n == 7) + test_function("Sort time", 10000000, test_sort); } diff --git a/bench/bench-qt.cpp b/bench/bench-qt.cpp index 9491eefc..331ebc86 100644 --- a/bench/bench-qt.cpp +++ b/bench/bench-qt.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -188,6 +189,19 @@ test_dict_big(unsigned long n) /********************************************************************************************/ +static void test_sort(size_t n) +{ + rand_init(); + QVector a1; + for(size_t i = 0; i < n; i++) { + a1.push_back(rand_get() ); + } + qSort(a1.begin(), a1.end()); + g_result = a1[0]; +} + +/********************************************************************************************/ + int main(int argc, const char *argv[]) { int n = (argc > 1) ? atoi(argv[1]) : 0; @@ -203,4 +217,6 @@ int main(int argc, const char *argv[]) test_function("Dict(u)time", 1000000, test_dict2); if (n == 6) test_function("DictB time", 1000000, test_dict_big); + if (n == 7) + test_function("Sort time", 10000000, test_sort); } diff --git a/bench/bench-stl.cpp b/bench/bench-stl.cpp index 2e82c988..4deaa5c0 100644 --- a/bench/bench-stl.cpp +++ b/bench/bench-stl.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -191,6 +192,19 @@ test_dict_big(unsigned long n) /********************************************************************************************/ +static void test_sort(size_t n) +{ + rand_init(); + vector a1; + for(size_t i = 0; i < n; i++) { + a1.push_back(rand_get() ); + } + sort(a1.begin(), a1.end()); + g_result = a1[0]; +} + +/********************************************************************************************/ + int main(int argc, const char *argv[]) { int n = (argc > 1) ? atoi(argv[1]) : 0; @@ -206,4 +220,6 @@ int main(int argc, const char *argv[]) test_function("Dict(u)time", 1000000, test_dict2); if (n == 6) test_function("DictB time", 1000000, test_dict_big); + if (n == 7) + test_function("Sort time", 10000000, test_sort); }