|
| 1 | +#include "bench.h" |
| 2 | +#include "ipp.h" |
| 3 | + |
| 4 | +template <typename T, class... Args> |
| 5 | +static void ippsort(benchmark::State &state, Args &&...args) |
| 6 | +{ |
| 7 | + auto args_tuple = std::make_tuple(std::move(args)...); |
| 8 | + size_t arrsize = std::get<0>(args_tuple); |
| 9 | + /* IPP set up */ |
| 10 | + int bufsize = 10; |
| 11 | + if constexpr (std::is_same_v<T, float>) { |
| 12 | + ippsSortRadixGetBufferSize(arrsize, ipp32f, &bufsize); |
| 13 | + } |
| 14 | + else if constexpr (std::is_same_v<T, double>) { |
| 15 | + ippsSortRadixGetBufferSize(arrsize, ipp64f, &bufsize); |
| 16 | + } |
| 17 | + unsigned char *temp = new unsigned char[bufsize]; |
| 18 | + |
| 19 | + // Get args |
| 20 | + std::string arrtype = std::get<1>(args_tuple); |
| 21 | + // set up array |
| 22 | + std::vector<T> arr = get_array<T>(arrtype, arrsize); |
| 23 | + std::vector<T> arr_bkp = arr; |
| 24 | + // benchmark |
| 25 | + for (auto _ : state) { |
| 26 | + if constexpr (std::is_same_v<T, float>) { |
| 27 | + ippsSortRadixAscend_32f_I(arr.data(), arrsize, temp); |
| 28 | + } |
| 29 | + else if constexpr (std::is_same_v<T, double>) { |
| 30 | + ippsSortRadixAscend_64f_I(arr.data(), arrsize, temp); |
| 31 | + } |
| 32 | + state.PauseTiming(); |
| 33 | + arr = arr_bkp; |
| 34 | + state.ResumeTiming(); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +template <typename T, class... Args> |
| 39 | +static void ippargsort(benchmark::State &state, Args &&...args) |
| 40 | +{ |
| 41 | + auto args_tuple = std::make_tuple(std::move(args)...); |
| 42 | + size_t arrsize = std::get<0>(args_tuple); |
| 43 | + /* IPP set up */ |
| 44 | + int bufsize = 10; |
| 45 | + if constexpr (std::is_same_v<T, float>) { |
| 46 | + ippsSortRadixIndexGetBufferSize(arrsize, ipp32f, &bufsize); |
| 47 | + } |
| 48 | + else if constexpr (std::is_same_v<T, double>) { |
| 49 | + ippsSortRadixIndexGetBufferSize(arrsize, ipp64f, &bufsize); |
| 50 | + } |
| 51 | + else if constexpr (std::is_same_v<T, int32_t>) { |
| 52 | + ippsSortRadixIndexGetBufferSize(arrsize, ipp32s, &bufsize); |
| 53 | + } |
| 54 | + unsigned char *temp = new unsigned char[bufsize]; |
| 55 | + |
| 56 | + // set up array |
| 57 | + std::string arrtype = std::get<1>(args_tuple); |
| 58 | + std::vector<T> arr = get_array<T>(arrtype, arrsize); |
| 59 | + std::vector<T> arr_bkp = arr; |
| 60 | + std::vector<int32_t> arg(arrsize); |
| 61 | + std::iota(arg.begin(), arg.end(), 0); |
| 62 | + |
| 63 | + // benchmark |
| 64 | + for (auto _ : state) { |
| 65 | + if constexpr (std::is_same_v<T, float>) { |
| 66 | + ippsSortRadixIndexAscend_32f(arr.data(), 4, arg.data(), arrsize, temp); |
| 67 | + } |
| 68 | + else if constexpr (std::is_same_v<T, double>) { |
| 69 | + ippsSortRadixIndexAscend_64f(arr.data(), 8, arg.data(), arrsize, temp); |
| 70 | + } |
| 71 | + else if constexpr (std::is_same_v<T, int32_t>) { |
| 72 | + ippsSortRadixIndexAscend_32s(arr.data(), 4, arg.data(), arrsize, temp); |
| 73 | + } |
| 74 | + state.PauseTiming(); |
| 75 | + arr = arr_bkp; |
| 76 | + std::iota(arg.begin(), arg.end(), 0); |
| 77 | + state.ResumeTiming(); |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +BENCH_SORT(ippsort, double) |
| 82 | +BENCH_SORT(ippsort, float) |
| 83 | +BENCH_SORT(ippargsort, double) |
| 84 | +BENCH_SORT(ippargsort, float) |
| 85 | +BENCH_SORT(ippargsort, int32_t) |
0 commit comments