From c2fc962766b782a32bd9fc563c967ceebd4ebd49 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Mon, 13 Dec 2021 03:48:01 +0100 Subject: [PATCH] test can now be used with perf valgrind --cachegrind and such tools --- test.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test.cpp b/test.cpp index ca3b32b..13c7d3c 100644 --- a/test.cpp +++ b/test.cpp @@ -7,7 +7,7 @@ // Number of input elements to generate - unused when CREEL is defined! //#define SORT_WIDTH 200000000 -#define SORT_WIDTH 40000 +#define SORT_WIDTH 4000000 // Uncomment this to use nibbles as digits and not bytes - CREEL defines this anyways //#define MAGYAR_SORT_NIBBLE @@ -16,6 +16,9 @@ #define SKA_SORT +// Uncomment for perf / cachegring and similar runs! +#define MEASURE_ONLY + /* Includes */ #include @@ -87,6 +90,7 @@ int main() { std::vector in1 = GenerateInput();; std::vector in2 = in1; // copy +#ifndef MEASURE_ONLY auto stdBegin = std::chrono::high_resolution_clock::now(); #ifndef SKA_SORT /* std::sort */ @@ -104,6 +108,8 @@ int main() { MagyarSort::debugArr(&in2[0], in2.size()); #endif // PRINT_OUTPUT +#endif // !MEASURE_ONLY + uint32_t *arr1 = &(in1[0]); #ifdef PRINT_OUTPUT @@ -124,18 +130,24 @@ int main() { /* Check against std - the real test */ bool good = true; +#ifndef MEASURE_ONLY for(size_t i = 0; good && (i < in1.size()); ++i) { good &= (in1[i] == in2[i]); } +#endif // !MEASURE_ONLY printf("Results:\n\n"); printf("- Sorted %zu elements", in1.size()); +#ifndef MEASURE_ONLY if(good) printf("- Same result as std::sort!\n"); else printf("- Differs from std::sort! Error!\n"); printf("\n"); auto stdElapsed = std::chrono::duration_cast(stdEnd - stdBegin); +#endif // !MEASURE_ONLY auto ourElapsed = std::chrono::duration_cast(ourEnd - ourBegin); +#ifndef MEASURE_ONLY printf("Time (std sort): %.3f ms.\n", stdElapsed.count() * 1e-6); +#endif // !MEASURE_ONLY printf("Time (our sort): %.3f ms.\n", ourElapsed.count() * 1e-6); return 0;