Skip to content

Commit

Permalink
Do not use custom macro for time measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
GabTux committed Mar 26, 2024
1 parent 8011b03 commit df27390
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 1 addition & 4 deletions include/ppqsort/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#include <bit>
#include <execution>


#define TIME_MEASURE

#ifndef NDEBUG
#include <bitset>
#include <iostream>
Expand Down Expand Up @@ -34,7 +31,7 @@
#define PRINT_ATOMIC_CPP(str)
#endif

#ifdef TIME_MEASURE
#ifdef PPQ_TIME_MEASURE
#include <chrono>
#define MEASURE_START(name) \
const std::chrono::steady_clock::time_point name = std::chrono::steady_clock::now();
Expand Down
20 changes: 13 additions & 7 deletions standalone/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ int main() {
}
std::vector input_std(input);

MEASURE_START(ppqsort_time_par);
auto start = std::chrono::steady_clock::now();
ppqsort::sort(ppqsort::execution::par, input.begin(), input.end());
MEASURE_END(ppqsort_time_par, "Parallel PPQSort time");
auto end = std::chrono::steady_clock::now();
std::cout << "Parallel PPQSort time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;

MEASURE_START(ppqsort_time);
std::sort(std::execution::par, input_std.begin(), input_std.end());
MEASURE_END(ppqsort_time, "std_sort time");
start = std::chrono::steady_clock::now();
std::sort(input_std.begin(), input_std.end());
end = std::chrono::steady_clock::now();
std::cout << "std::sort time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;

std::cout << "sorted: ";
for (int i = 0; i < max_size; ++i) {
Expand All @@ -51,8 +55,10 @@ int main() {
}

// enforce branchless variant for strings
MEASURE_START(ppqsort_time_par_str);
start = std::chrono::steady_clock::now();
ppqsort::sort(ppqsort::execution::par_force_branchless, input_str.begin(), input_str.end());
MEASURE_END(ppqsort_time_par_str, "Parallel PPQSort time string");
end = std::chrono::steady_clock::now();
std::cout << "Parallel PPQSort time, strings: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms" << std::endl;
return !std::ranges::is_sorted(input_str);
}

0 comments on commit df27390

Please sign in to comment.