Skip to content

Commit

Permalink
Add benchmarks for keyvalue sort
Browse files Browse the repository at this point in the history
  • Loading branch information
r-devulap committed Nov 17, 2023
1 parent b8600a4 commit aba8371
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions benchmarks/bench-all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
#include "bench-partial-qsort.hpp"
#include "bench-qselect.hpp"
#include "bench-qsort.hpp"
#include "bench-keyvalue.hpp"
48 changes: 48 additions & 0 deletions benchmarks/bench-keyvalue.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "x86simdsort-scalar.h"

template <typename T, class... Args>
static void scalarkvsort(benchmark::State &state, Args &&...args)
{
// Get args
auto args_tuple = std::make_tuple(std::move(args)...);
size_t arrsize = std::get<0>(args_tuple);
std::string arrtype = std::get<1>(args_tuple);
// set up array
std::vector<T> key = get_array<T>(arrtype, arrsize);
std::vector<T> val = get_array<T>("random", arrsize);
std::vector<T> key_bkp = key;
// benchmark
for (auto _ : state) {
xss::scalar::keyvalue_qsort(key.data(), val.data(), arrsize, false);
state.PauseTiming();
key = key_bkp;
state.ResumeTiming();
}
}

template <typename T, class... Args>
static void simdkvsort(benchmark::State &state, Args &&...args)
{
auto args_tuple = std::make_tuple(std::move(args)...);
size_t arrsize = std::get<0>(args_tuple);
std::string arrtype = std::get<1>(args_tuple);
// set up array
std::vector<T> key = get_array<T>(arrtype, arrsize);
std::vector<T> val = get_array<T>("random", arrsize);
std::vector<T> key_bkp = key;
// benchmark
for (auto _ : state) {
x86simdsort::keyvalue_qsort(key.data(), val.data(), arrsize);
state.PauseTiming();
key = key_bkp;
state.ResumeTiming();
}
}

#define BENCH_BOTH_KVSORT(type) \
BENCH_SORT(simdkvsort, type) \
BENCH_SORT(scalarkvsort, type)

BENCH_BOTH_KVSORT(uint64_t)
BENCH_BOTH_KVSORT(int64_t)
BENCH_BOTH_KVSORT(double)
3 changes: 3 additions & 0 deletions run-bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
elif "argsort" in args.benchcompare:
baseline = "scalarargsort.*" + filterb
contender = "simdargsort.*" + filterb
elif "keyvalue" in args.benchcompare:
baseline = "scalarkvsort.*" + filterb
contender = "simdkvsort.*" + filterb
else:
parser.print_help(sys.stderr)
parser.error("ERROR: Unknown argument '%s'" % args.benchcompare)
Expand Down

0 comments on commit aba8371

Please sign in to comment.