Skip to content
Closed
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
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(objc_msgSend objc_msgSend.cpp TestClass.m)

target_compile_options(objc_msgSend PRIVATE "-fobjc-runtime=gnustep-2.0")
target_link_libraries(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
23 changes: 23 additions & 0 deletions benchmarks/objc_msgSend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <benchmark/benchmark.h>
#include "../objc/runtime.h"
#include <assert.h>

static id testClass;
static SEL answerSel;

static void objc_msgSendSetup(const benchmark::State& state) {
testClass = objc_getClass("TestClass");
answerSel = sel_registerName("answer");
}

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

BENCHMARK_MAIN();
2 changes: 2 additions & 0 deletions objc_msgSend.x86-64.S
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
mov (\receiver), %r10 # Load the dtable from the class
1: # classLoaded
mov DTABLE_OFFSET(%r10), %r10 # Load the dtable from the class into r10
test %r10, %r10 # If the dtable is nil
jz 4f # return nil
mov %rax, -8(%rsp) # %rax contains information for variadic calls
mov %rbx, -16(%rsp) # On the fast path, spill into the red zone
mov (\sel), %eax # Load the selector index into %eax
Expand Down
Loading