Skip to content

Commit

Permalink
Changed: Simd restricted to 128bit operations
Browse files Browse the repository at this point in the history
  • Loading branch information
WillisMedwell committed Feb 5, 2024
1 parent 5b30358 commit ada17ef
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 135 deletions.
64 changes: 33 additions & 31 deletions benchmark/BenchSimd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ auto iota(size_t max) -> std::vector<int32_t> {
const static std::vector<int32_t> NUMS = iota(10000);


static void BM_Utily_Simd_find_char(benchmark::State& state) {
static void BM_Uty_find_char(benchmark::State& state) {
for (auto _ : state) {
volatile auto iter = Utily::Simd::find(LONG_STRING.begin(), LONG_STRING.end(), 'z');
volatile auto iter = Utily::Simd128::Char::find(LONG_STRING.data(), LONG_STRING.size(), 'z');
benchmark::DoNotOptimize(iter);
}
}
BENCHMARK(BM_Utily_Simd_find_char);
BENCHMARK(BM_Uty_find_char);

static void BM_Std_find_char(benchmark::State& state) {
for (auto _ : state) {
volatile auto iter = std::find(LONG_STRING.begin(), LONG_STRING.end(), 'z');
Expand All @@ -48,14 +49,17 @@ static void BM_Std_find_char(benchmark::State& state) {
}
BENCHMARK(BM_Std_find_char);

static void BM_Utily_Simd_find_first_of_char(benchmark::State& state) {


static void BM_Uty_find_first_of_char(benchmark::State& state) {
const auto data = std::to_array({ 'z', 'o', 'n' });
for (auto _ : state) {
volatile auto iter = Utily::Simd::find_first_of(LONG_STRING.begin(), LONG_STRING.end(), data.begin(), data.end());
volatile auto iter = Utily::Simd128::Char::find_first_of(LONG_STRING.data(), LONG_STRING.size(), data.data(), data.size());
benchmark::DoNotOptimize(iter);
}
}
BENCHMARK(BM_Utily_Simd_find_first_of_char);
BENCHMARK(BM_Uty_find_first_of_char);

static void BM_Std_find_first_of_chars(benchmark::State& state) {
const auto data = std::to_array({ 'z', 'o', 'n' });
for (auto _ : state) {
Expand All @@ -67,39 +71,37 @@ static void BM_Std_find_first_of_chars(benchmark::State& state) {
}
BENCHMARK(BM_Std_find_first_of_chars);

static void BM_Utily_Simd_find_int32(benchmark::State& state) {
for (auto _ : state) {
volatile auto iter = Utily::Simd::find(NUMS.begin(), NUMS.begin(), NUMS.back());
benchmark::DoNotOptimize(iter);
}
}
BENCHMARK(BM_Utily_Simd_find_int32);
// static void BM_Uty_find_int32(benchmark::State& state) {
// for (auto _ : state) {
// volatile auto iter = Utily::Simd128::Char::find(NUMS.data(), NUMS.size(), NUMS.back());
// benchmark::DoNotOptimize(iter);
// }
// }
// BENCHMARK(BM_Uty_find_int32);

static void BM_Std_find_int32(benchmark::State& state) {
for (auto _ : state) {
volatile auto iter = std::find(NUMS.begin(), NUMS.begin(), NUMS.back());
benchmark::DoNotOptimize(iter);
}
}
BENCHMARK(BM_Std_find_int32);
// static void BM_Std_find_int32(benchmark::State& state) {
// for (auto _ : state) {
// volatile auto iter = std::find(NUMS.begin(), NUMS.begin(), NUMS.back());
// benchmark::DoNotOptimize(iter);
// }
// }
// BENCHMARK(BM_Std_find_int32);


static void BM_Utily_find_subrange_char_4letters(benchmark::State& state) {
static void BM_Uty_search_char_4letters(benchmark::State& state) {
std::string_view find = "stri";
for (auto _ : state) {
volatile auto iter = Utily::Simd::find_subrange(
LONG_STRING.begin(),
LONG_STRING.end(),
find.begin(),
find.end());
volatile auto iter = Utily::Simd128::Char::search(
LONG_STRING.data(),
LONG_STRING.size(),
find.data(),
find.size());
benchmark::DoNotOptimize(iter);
}
}
BENCHMARK(BM_Utily_find_subrange_char_4letters);


BENCHMARK(BM_Uty_search_char_4letters);

static void BM_std_find_subrange_char_4letters(benchmark::State& state) {
static void BM_Std_search_char_4letters(benchmark::State& state) {
std::string_view find = "stri";
for (auto _ : state) {
volatile auto iter = std::search(
Expand All @@ -110,6 +112,6 @@ static void BM_std_find_subrange_char_4letters(benchmark::State& state) {
benchmark::DoNotOptimize(iter);
}
}
BENCHMARK(BM_std_find_subrange_char_4letters);
BENCHMARK(BM_Std_search_char_4letters);

#endif
6 changes: 3 additions & 3 deletions build-all.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ if not exist "build-native\" (
mkdir build-native
)
cd build-native
call cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DBUILD_UTILY_TESTS=1 -DBUILD_UTILY_BENCHMARKS=1
call cmake --build . --config Debug
call cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DBUILD_UTILY_TESTS=1 -DBUILD_UTILY_BENCHMARKS=1
call cmake --build . --config Release
cd ..

@REM WEB
Expand All @@ -22,4 +22,4 @@ cd ..

cd build-native
call UtilyTest.exe
@REM call UtilyBenchmark.exe
call UtilyBenchmark.exe
Loading

0 comments on commit ada17ef

Please sign in to comment.