Skip to content

Commit b3529a0

Browse files
committed
Add benchmark
1 parent 0c1a893 commit b3529a0

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

benchmarks/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
find_package(benchmark REQUIRED)
2+
3+
add_executable(objc_msgSend objc_msgSend.cpp TestClass.m)
4+
5+
target_compile_options(objc_msgSend PRIVATE "-fobjc-runtime=gnustep-2.0")
6+
target_link_libraries(objc_msgSend benchmark::benchmark objc)

benchmarks/TestClass.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@interface TestClass
2+
- (int)answer;
3+
@end
4+
5+
@implementation TestClass
6+
- (int)answer
7+
{
8+
return 42;
9+
}
10+
@end

benchmarks/objc_msgSend.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <benchmark/benchmark.h>
2+
#include "../objc/runtime.h"
3+
#include <assert.h>
4+
5+
static id testClass;
6+
static SEL answerSel;
7+
8+
static void objc_msgSendSetup(const benchmark::State& state) {
9+
testClass = objc_getClass("TestClass");
10+
answerSel = sel_registerName("answer");
11+
}
12+
13+
static void objc_msgSend(benchmark::State& state) {
14+
for (auto _ : state)
15+
{
16+
id a = objc_msgSend(testClass, answerSel);
17+
assert((uintptr_t)a == 42);
18+
}
19+
}
20+
// Register the function as a benchmark
21+
BENCHMARK(objc_msgSend)->Setup(objc_msgSendSetup)->Repetitions(25);
22+
23+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)