diff options
Diffstat (limited to 'tests/embind/embind_benchmark.cpp')
-rw-r--r-- | tests/embind/embind_benchmark.cpp | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/tests/embind/embind_benchmark.cpp b/tests/embind/embind_benchmark.cpp index b6a834c9..5ae9a6be 100644 --- a/tests/embind/embind_benchmark.cpp +++ b/tests/embind/embind_benchmark.cpp @@ -50,6 +50,14 @@ extern void pass_gameobject_ptr_benchmark_embind_js(); extern void call_through_interface0(); extern void call_through_interface1(); +extern void call_through_interface2(); + +extern void returns_val_benchmark(); +} + +emscripten::val returns_val(emscripten::val value) +{ + return emscripten::val(value.as<unsigned>() + 1); } class Vec3 @@ -135,19 +143,45 @@ class Interface public: virtual void call0() = 0; virtual std::wstring call1(const std::wstring& str1, const std::wstring& str2) = 0; + virtual void call_with_typed_array(size_t size, const void*) = 0; + virtual void call_with_memory_view(size_t size, const void*) = 0; }; +EMSCRIPTEN_SYMBOL(HEAP8); +EMSCRIPTEN_SYMBOL(buffer); + +EMSCRIPTEN_SYMBOL(call0); +EMSCRIPTEN_SYMBOL(call1); +EMSCRIPTEN_SYMBOL(call_with_typed_array); +EMSCRIPTEN_SYMBOL(call_with_memory_view); +EMSCRIPTEN_SYMBOL(Uint8Array); + class InterfaceWrapper : public emscripten::wrapper<Interface> { public: EMSCRIPTEN_WRAPPER(InterfaceWrapper); void call0() override { - return call<void>("call0"); + return call<void>(call0_symbol); } std::wstring call1(const std::wstring& str1, const std::wstring& str2) { - return call<std::wstring>("call1", str1, str2); + return call<std::wstring>(call1_symbol, str1, str2); + } + + void call_with_typed_array(size_t size, const void* data) { + return call<void>( + call_with_typed_array_symbol, + emscripten::val::global(Uint8Array_symbol).new_( + emscripten::val::module_property(HEAP8_symbol)[buffer_symbol], + reinterpret_cast<uintptr_t>(data), + size)); + } + + void call_with_memory_view(size_t size, const void* data) { + return call<void>( + call_with_memory_view_symbol, + emscripten::memory_view(size, data)); } }; @@ -180,6 +214,33 @@ void callInterface1(unsigned N, Interface& o) { } } +void callInterface2(unsigned N, Interface& o) { + int i = 0; + for (unsigned i = 0; i < N; i += 8) { + o.call_with_typed_array(sizeof(int), &i); + o.call_with_typed_array(sizeof(int), &i); + o.call_with_typed_array(sizeof(int), &i); + o.call_with_typed_array(sizeof(int), &i); + o.call_with_typed_array(sizeof(int), &i); + o.call_with_typed_array(sizeof(int), &i); + o.call_with_typed_array(sizeof(int), &i); + o.call_with_typed_array(sizeof(int), &i); + } +} + +void callInterface3(unsigned N, Interface& o) { + for (unsigned i = 0; i < N; i += 8) { + o.call_with_memory_view(sizeof(int), &i); + o.call_with_memory_view(sizeof(int), &i); + o.call_with_memory_view(sizeof(int), &i); + o.call_with_memory_view(sizeof(int), &i); + o.call_with_memory_view(sizeof(int), &i); + o.call_with_memory_view(sizeof(int), &i); + o.call_with_memory_view(sizeof(int), &i); + o.call_with_memory_view(sizeof(int), &i); + } +} + EMSCRIPTEN_BINDINGS(benchmark) { using namespace emscripten; @@ -225,6 +286,10 @@ EMSCRIPTEN_BINDINGS(benchmark) function("callInterface0", &callInterface0); function("callInterface1", &callInterface1); + function("callInterface2", &callInterface2); + function("callInterface3", &callInterface3); + + function("returns_val", &returns_val); } void __attribute__((noinline)) emscripten_get_now_benchmark(int N) @@ -435,4 +500,6 @@ int main() emscripten_get_now(); call_through_interface0(); call_through_interface1(); + call_through_interface2(); + returns_val_benchmark(); } |