Skip to content

Commit

Permalink
WIP/measurement
Browse files Browse the repository at this point in the history
melton1968 committed Jun 12, 2023
1 parent 722419b commit fd8365e
Showing 2 changed files with 78 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ file(GLOB_RECURSE PUBLIC_INCLUDE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} incl
target_sources(sort INTERFACE FILE_SET HEADERS BASE_DIRS include FILES ${PUBLIC_INCLUDE_FILES})

target_include_directories(sort PUBLIC ${GMP_INCLUDE_DIRS})
target_link_libraries(sort PUBLIC record::record timer::timer fmt::fmt)
target_link_libraries(sort PUBLIC record::record timer::timer fmt::fmt argparse::argparse)

foreach(prog
example0
100 changes: 77 additions & 23 deletions src/tools/measure_sequential.cpp
Original file line number Diff line number Diff line change
@@ -7,10 +7,54 @@
#include "core/timer/timer.h"
#include "core/sort/qsort.h"
#include "boost/sort/sort.hpp"
#include "core/argparse/argp.h"
#include "core/lexical_cast/lexical_cast.h"

using std::cout, std::endl;
using core::argp::ArgParse, core::argp::argFlag, core::argp::argValue;
using namespace core;

struct NumberRange {
NumberRange(size_t n)
: start(n)
, stop(n)
, step(1) {
}

NumberRange(size_t arg_start, size_t arg_stop, size_t arg_step = 1)
: start(arg_start)
, stop(arg_stop)
, step(arg_step) {
}

size_t start, stop, step;
};

template<class T>
auto split(std::string_view str, char delim) {
std::vector<T> strs;
for (size_t begin = 0; begin < str.size();) {
auto tail = str.substr(begin);
auto end = tail.find(delim);
strs.emplace_back(core::lexical_cast<T>(tail.substr(0, end)));
begin = end == std::string_view::npos ? str.size() : begin + end + 1;
}
return strs;
}

namespace core::lexical_cast_detail {
template<>
struct lexical_cast_impl<NumberRange> {
static NumberRange parse(std::string_view input) {
auto values = split<uint64_t>(input, ':');
auto start = values[0];
auto stop = values.size() > 1 ? values[1] : start;
auto step = values.size() > 2 ? values[2] : 1;
return NumberRange(start, stop, step);
}
};
}; // core::lexical_cast_detail

template<class Work>
void measure(std::string_view desc, size_t nrecords, Work&& work) {
std::uniform_int_distribution<uint64_t> d;
@@ -36,31 +80,41 @@ void measure(std::string_view desc, size_t nrecords, Work&& work) {
}

int main(int argc, const char *argv[]) {
size_t nrecords = argc < 2 ? 10'000'000 : atoi(argv[1]);
ArgParse opts
(
argValue<'n'>("counts", NumberRange{1000}, "Range of record count"),
argFlag<'v'>("verbose", "Verbose diagnostics")
);
opts.parse(argc, argv);
auto counts = opts.get<'n'>();
// auto verbose = opts.get<'v'>();

measure("std::sort", nrecords, [](auto begin, auto end) {
std::sort(begin, end);
});

measure("core::sort::qsort", nrecords, [](auto begin, auto end) {
sort::qsort(begin, end);
});

measure("boost::sort::flat_stable_sort", nrecords, [](auto begin, auto end) {
boost::sort::flat_stable_sort(begin, end);
});

measure("boost::sort::pdqsort", nrecords, [](auto begin, auto end) {
boost::sort::pdqsort(begin, end);
});

measure("boost::sort::spinsort", nrecords, [](auto begin, auto end) {
boost::sort::spinsort(begin, end);
});
for (auto nrecords = counts.start; nrecords <= counts.stop; nrecords += counts.step) {

measure("boost::sort::spreadsort", nrecords, [](auto begin, auto end) {
boost::sort::spinsort(begin, end);
});
measure("std::sort", nrecords, [](auto begin, auto end) {
std::sort(begin, end);
});

measure("core::sort::qsort", nrecords, [](auto begin, auto end) {
sort::qsort(begin, end);
});

measure("boost::sort::flat_stable_sort", nrecords, [](auto begin, auto end) {
boost::sort::flat_stable_sort(begin, end);
});

measure("boost::sort::pdqsort", nrecords, [](auto begin, auto end) {
boost::sort::pdqsort(begin, end);
});

measure("boost::sort::spinsort", nrecords, [](auto begin, auto end) {
boost::sort::spinsort(begin, end);
});

measure("boost::sort::spreadsort", nrecords, [](auto begin, auto end) {
boost::sort::spinsort(begin, end);
});
}

return 0;
}

0 comments on commit fd8365e

Please sign in to comment.