Skip to content

Add benchmarks #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt install ninja-build
sudo apt install ninja-build libbenchmark-dev
if [ "${{ matrix.cxxlib }}" = "libc++" ]; then
sudo apt remove -y 'libc++*'
apt search libunwind
Expand All @@ -71,7 +71,7 @@ jobs:
export EMBEDDED_BLOCKS_RUNTIME=ON
fi
ls -lahR /usr/lib/llvm-${{ matrix.llvm-version }}/lib/
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -G Ninja -DTESTS=ON -DEMBEDDED_BLOCKS_RUNTIME=$EMBEDDED_BLOCKS_RUNTIME -DCMAKE_C_COMPILER=clang-${{matrix.llvm-version}} -DCMAKE_OBJC_COMPILER=clang-${{matrix.llvm-version}} -DCMAKE_ASM_COMPILER=clang-${{matrix.llvm-version}} -DCMAKE_CXX_COMPILER=clang++-${{matrix.llvm-version}} -DCMAKE_OBJCXX_COMPILER=clang++-${{matrix.llvm-version}} -DCMAKE_CXX_FLAGS="-stdlib=${{matrix.cxxlib}}"
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -G Ninja -DTESTS=ON -DBENCHMARKS=ON -DEMBEDDED_BLOCKS_RUNTIME=$EMBEDDED_BLOCKS_RUNTIME -DCMAKE_C_COMPILER=clang-${{matrix.llvm-version}} -DCMAKE_OBJC_COMPILER=clang-${{matrix.llvm-version}} -DCMAKE_ASM_COMPILER=clang-${{matrix.llvm-version}} -DCMAKE_CXX_COMPILER=clang++-${{matrix.llvm-version}} -DCMAKE_OBJCXX_COMPILER=clang++-${{matrix.llvm-version}} -DCMAKE_CXX_FLAGS="-stdlib=${{matrix.cxxlib}}"
# Build with a nice ninja status line
- name: Build
working-directory: ${{github.workspace}}/build
Expand All @@ -81,6 +81,11 @@ jobs:
working-directory: ${{github.workspace}}/build
run: |
ctest --output-on-failure -j 4
- name: Benchmark
working-directory: ${{github.workspace}}/build
run: |
./benchmarks/benchmark_objc_msgSend
if: matrix.cxxlib == 'libstdc++'

qemu-crossbuild:
strategy:
Expand Down Expand Up @@ -237,12 +242,12 @@ jobs:
with:
msystem: ${{ matrix.msystem }}
update: true
install: git mingw-w64-${{ matrix.package-prefix }}-clang mingw-w64-${{ matrix.package-prefix }}-lld mingw-w64-${{ matrix.package-prefix }}-cmake
install: git mingw-w64-${{ matrix.package-prefix }}-clang mingw-w64-${{ matrix.package-prefix }}-lld mingw-w64-${{ matrix.package-prefix }}-cmake mingw-w64-${{ matrix.package-prefix }}-benchmark
- name: Configure CMake
run: |
mkdir build
cd build
${{ matrix.cmake-flags }} cmake .. -DTESTS=ON -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DSTRICT_APPLE_COMPATIBILITY=${{ matrix.strict-apple-compatibility }}
${{ matrix.cmake-flags }} cmake .. -DTESTS=ON -DBENCHMARKS=ON -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DSTRICT_APPLE_COMPATIBILITY=${{ matrix.strict-apple-compatibility }}
- name: Build
working-directory: build
run: |
Expand All @@ -251,6 +256,10 @@ jobs:
working-directory: build
run: |
ctest -j 4 --output-on-failure -T test ${{ matrix.ctest-flags }}
- name: Benchmark
working-directory: build
run: |
./benchmarks/benchmark_objc_msgSend.exe
- name: Install
working-directory: build
run: |
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ option(DEBUG_ARC_COMPAT
"Log warnings for classes that don't hit ARC fast paths" OFF)
option(ENABLE_OBJCXX "Enable support for Objective-C++" ON)
option(TESTS "Enable building the tests")
option(BENCHMARKS "Enable building the benchmarks" OFF)
option(EMBEDDED_BLOCKS_RUNTIME "Include an embedded blocks runtime, rather than relying on libBlocksRuntime to supply it" ON)
option(STRICT_APPLE_COMPATIBILITY "Use strict Apple compatibility, always defining BOOL as signed char" OFF)

Expand Down Expand Up @@ -448,6 +449,10 @@ if (TESTS)
add_subdirectory(Test)
endif (TESTS)

if (BENCHMARKS)
add_subdirectory(benchmarks)
endif()

CHECK_CXX_SOURCE_COMPILES("
#include <stdlib.h>
extern \"C\" {
Expand Down
6 changes: 6 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
find_package(benchmark REQUIRED)

add_executable(benchmark_objc_msgSend objc_msgSend.cpp TestClass.m)

target_compile_options(benchmark_objc_msgSend PRIVATE "-fobjc-runtime=gnustep-2.0")
target_link_libraries(benchmark_objc_msgSend benchmark::benchmark objc)
10 changes: 10 additions & 0 deletions benchmarks/TestClass.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@interface TestClass
- (int)answer;
@end

@implementation TestClass
- (int)answer
{
return 42;
}
@end
20 changes: 20 additions & 0 deletions benchmarks/objc_msgSend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <benchmark/benchmark.h>
#include "../objc/runtime.h"
#include <assert.h>

static id testClass;
static SEL answerSel;

static void objc_msgSend(benchmark::State& state) {
id testClass = objc_getClass("TestClass");
SEL answerSel = sel_registerName("answer");
for (auto _ : state)
{
id a = objc_msgSend(testClass, answerSel);
assert((uintptr_t)a == 42);
}
}
// Register the function as a benchmark
BENCHMARK(objc_msgSend)->Repetitions(25);

BENCHMARK_MAIN();
Loading