test can now be used with perf valgrind --cachegrind and such tools

This commit is contained in:
Richard Thier 2021-12-13 03:48:01 +01:00
parent bcdb905748
commit c2fc962766

View File

@ -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 <cstring>
@ -87,6 +90,7 @@ int main() {
std::vector<uint32_t> in1 = GenerateInput();;
std::vector<uint32_t> 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<std::chrono::nanoseconds>(stdEnd - stdBegin);
#endif // !MEASURE_ONLY
auto ourElapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(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;