Skip to content

Commit

Permalink
Added WebAssembly Benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
WillisMedwell committed Feb 7, 2024
1 parent d7bb914 commit 99021f6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/.clang-format DESTINATION ${CMAKE_CURRENT_
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

if(DEFINED EMSCRIPTEN)
message(STATUS "For Emscripten SIMD use flags: \"-msimd128 -mrelaxed-simd -msse -msse2 -msse3 -mavx\"")
message(STATUS "For Emscripten SIMD use flags: \"-msimd128 -mrelaxed-simd -msse -msse2 -msse3 -msse4.1\"")
elseif(NOT MSVC)
target_compile_options(Utily_Utily PRIVATE "-Wall" "-Wextra" "-Wpedantic" "-Wcast-align" "-Wcast-qual" "-Wctor-dtor-privacy" "-Wformat=2" "-Winit-self" "-Wmissing-declarations" "-Wmissing-include-dirs" "-Wold-style-cast" "-Woverloaded-virtual" "-Wredundant-decls" "-Wshadow" "-Wsign-conversion" "-Wsign-promo" "-Wstrict-overflow=5" "-Wundef" "-Wno-unused" "-Wconversion" "-Wsign-compare")
message(STATUS "For Native SIMD use flags: \"-march=native\"")
Expand Down Expand Up @@ -53,7 +53,7 @@ if(BUILD_UTILY_TESTS)
add_executable(UtilyTest ${UTILY_TEST_SOURCES})
if(DEFINED EMSCRIPTEN)
target_compile_options(UtilyTest PRIVATE "-Wdeprecated-declarations")
target_compile_options(UtilyTest PRIVATE -msimd128 -mrelaxed-simd -msse -msse2 -msse3 -mavx)
target_compile_options(UtilyTest PRIVATE -msimd128 -mrelaxed-simd -msse -msse2 -msse3 -msse4.1)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
elseif(NOT MSVC)
target_compile_options(UtilyTest PRIVATE "-Wall" "-Wextra" "-Wpedantic" "-Wcast-align" "-Wcast-qual" "-Wctor-dtor-privacy" "-Wformat=2" "-Winit-self" "-Wmissing-declarations" "-Wmissing-include-dirs" "-Wold-style-cast" "-Woverloaded-virtual" "-Wredundant-decls" "-Wshadow" "-Wsign-conversion" "-Wsign-promo" "-Wstrict-overflow=5" "-Wundef" "-Wno-unused" "-Wconversion" "-Wsign-compare")
Expand Down Expand Up @@ -103,7 +103,7 @@ if(BUILD_UTILY_BENCHMARKS)
endforeach()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PRELOAD_FILES} -Wno-unused-command-line-argument")
target_compile_options(UtilyBenchmark PRIVATE -Wno-deprecated-declarations -Wno-unused-command-line-argument)
target_compile_options(UtilyBenchmark PRIVATE -msimd128 -mrelaxed-simd -msse -msse2 -msse3 -mavx)
target_compile_options(UtilyBenchmark PRIVATE -msimd128 -mrelaxed-simd -msse -msse2 -msse3 -msse4.1)
elseif(NOT MSVC)
target_compile_options(UtilyBenchmark PRIVATE "-Wall" "-Wextra" "-Wpedantic" "-Wcast-align" "-Wcast-qual" "-Wctor-dtor-privacy" "-Wformat=2" "-Winit-self" "-Wmissing-declarations" "-Wmissing-include-dirs" "-Wold-style-cast" "-Woverloaded-virtual" "-Wredundant-decls" "-Wshadow" "-Wsign-conversion" "-Wsign-promo" "-Wstrict-overflow=5" "-Wswitch-default" "-Wundef" "-Wno-unused" "-Wconversion" "-Wsign-compare")
target_compile_options(UtilyBenchmark PRIVATE -mtune=native)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ constexpr auto to_array(Args&&... args)

**Emscripten**

| String Operation | Std | StringZilla | Utily |
| ----------------------- | --- | ----------- | ----- |
| find | | | |
| find_first_of | | | |
| find_substring(char[4]) | | | |
| find_substring(char[8]) | | | |
| String Operation | Std | StringZilla | Utily |
| ----------------------- | ------- | ----------- | ----------- |
| find | 405 ns | | **22.3 ns** |
| find_first_of | 1555 ns | | **136 ns** |
| find_substring(char[4]) | 1110 ns | | **196 ns** |
| find_substring(char[8]) | 938 ns | | **574 ns** |

*NOTE: Only 128bit vector operations supported. *

Expand Down
1 change: 1 addition & 0 deletions benchmark/BenchSimd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static void BM_Uty_search_char_4letters(benchmark::State& state) {
}
}
BENCHMARK(BM_Uty_search_char_4letters);

#ifndef EMSCRIPTEN
static void BM_Zil_search_char_4letters(benchmark::State& state) {
std::string_view find = "stri";
Expand Down
31 changes: 17 additions & 14 deletions build-all.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@

@echo off
set VCPKG_PATH=C:/apps/vcpkg/vcpkg/
set EMSDK=C:/apps/emscripten/emsdk/
set EMSCRIPTEN=C:/apps/emscripten/emsdk/upstream/emscripten/
set BUILD_TYPE=Release

@REM NATIVE
if not exist "build-native\" (
mkdir build-native
)
cd build-native
call cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DBUILD_UTILY_TESTS=1 -DBUILD_UTILY_BENCHMARKS=1
call cmake --build . --config Release
cd ..

@REM WEB
@REM if not exist "build/emscripten-ninja" (
@REM mkdir build/emscripten-ninja
@REM if not exist "build-native\" (
@REM mkdir build-native
@REM )
@REM call emcmake cmake --preset emscripten-ninja -DCMAKE_SUPPRESS_DEVELOPER_WARNINGS=ON
@REM call cmake --build build/emscripten-ninja --config Release
@REM cd build-native
@REM call cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DBUILD_UTILY_TESTS=1 -DBUILD_UTILY_BENCHMARKS=1 -DCMAKE_BUILD_TYPE=%BUILD_TYPE%
@REM call cmake --build . --config %BUILD_TYPE%
@REM cd ..

if not exist "build-web\" (
mkdir build-web
)
cd build-web
call emcmake cmake .. -DBUILD_UTILY_TESTS=1 -DBUILD_UTILY_BENCHMARKS=1 -DCMAKE_TOOLCHAIN_FILE=%VCPKG_PATH%/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=wasm32-emscripten -DEMSCRIPTEN=1 -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=%EMSCRIPTEN%cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=%BUILD_TYPE%
call cmake --build . --config %BUILD_TYPE%
cd ..

cd build-native
call UtilyTest.exe
@REM call UtilyTest.exe
@REM call UtilyBenchmark.exe
4 changes: 2 additions & 2 deletions test/UnitTypeErasedVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
TEST(TypeErasedVector, Constructor) {
{
auto vector = Utily::TypeErasedVector {};
#ifndef NDEBUG
#if !defined(NDEBUG) && !defined(EMSCRIPTEN)
EXPECT_DEBUG_DEATH(vector.emplace_back<int>(1), "");
#endif
vector.set_underlying_type<float>();
Expand Down Expand Up @@ -39,7 +39,7 @@ TEST(TypeErasedVector, push_back) {
EXPECT_EQ(vector.size_bytes(), 0);
EXPECT_EQ(vector.capacity(), 0);

#ifndef NDEBUG
#if !defined(NDEBUG) && !defined(EMSCRIPTEN)
EXPECT_DEBUG_DEATH(vector.emplace_back<int>(1), "");
EXPECT_DEBUG_DEATH(vector.emplace_back<double>(1), "");
#endif
Expand Down

0 comments on commit 99021f6

Please sign in to comment.