File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 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)
Original file line number Diff line number Diff line change 1+ @interface TestClass
2+ - (int )answer ;
3+ @end
4+
5+ @implementation TestClass
6+ - (int )answer
7+ {
8+ return 42 ;
9+ }
10+ @end
Original file line number Diff line number Diff line change 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 ();
You can’t perform that action at this time.
0 commit comments