aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-05-03 18:51:01 -0700
committerChad Austin <chad@imvu.com>2013-05-17 12:57:04 -0700
commita020f7dc1d37e986a2ce26a960ec1c1be5734f97 (patch)
treef21a0d8eb8c7f0fb9b152f32b30cbd79ca744a6b /tests
parenta27e5f7cc22e64fa9a32a68f9fd732c0ea5013ad (diff)
Benchmark for memory_view
Diffstat (limited to 'tests')
-rw-r--r--tests/embind/embind.benchmark.js24
-rw-r--r--tests/embind/embind_benchmark.cpp51
2 files changed, 75 insertions, 0 deletions
diff --git a/tests/embind/embind.benchmark.js b/tests/embind/embind.benchmark.js
index 7b20db88..a21b8392 100644
--- a/tests/embind/embind.benchmark.js
+++ b/tests/embind/embind.benchmark.js
@@ -248,3 +248,27 @@ function _call_through_interface1() {
Module.print("C++ -> JS std::wstring through interface " + N + " iters: " + elapsed + " msecs.");
obj.delete();
}
+
+function _call_through_interface2() {
+ var N = 1000000;
+ var total = 0;
+ var obj = Module['Interface'].implement({
+ call_with_typed_array: function(ta) {
+ total += ta.length;
+ },
+ call_with_memory_view: function(ta) {
+ total += ta.length;
+ },
+ });
+
+ var start = _emscripten_get_now();
+ Module['callInterface2'](N, obj);
+ var elapsed = _emscripten_get_now() - start;
+ Module.print("C++ -> JS typed array instantiation " + N + " iters: " + elapsed + " msecs.");
+
+ var start = _emscripten_get_now();
+ Module['callInterface3'](N, obj);
+ var elapsed = _emscripten_get_now() - start;
+ Module.print("C++ -> JS memory_view instantiation" + N + " iters: " + elapsed + " msecs.");
+ obj.delete();
+}
diff --git a/tests/embind/embind_benchmark.cpp b/tests/embind/embind_benchmark.cpp
index b6a834c9..5ad41654 100644
--- a/tests/embind/embind_benchmark.cpp
+++ b/tests/embind/embind_benchmark.cpp
@@ -50,6 +50,7 @@ extern void pass_gameobject_ptr_benchmark_embind_js();
extern void call_through_interface0();
extern void call_through_interface1();
+extern void call_through_interface2();
}
class Vec3
@@ -135,8 +136,13 @@ 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);
+
class InterfaceWrapper : public emscripten::wrapper<Interface>
{
public:
@@ -149,6 +155,21 @@ public:
std::wstring call1(const std::wstring& str1, const std::wstring& str2) {
return call<std::wstring>("call1", str1, str2);
}
+
+ void call_with_typed_array(size_t size, const void* data) {
+ return call<void>(
+ "call_with_typed_array",
+ emscripten::val::global("Uint8Array").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",
+ emscripten::memory_view(size, data));
+ }
};
void callInterface0(unsigned N, Interface& o) {
@@ -180,6 +201,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 +273,8 @@ EMSCRIPTEN_BINDINGS(benchmark)
function("callInterface0", &callInterface0);
function("callInterface1", &callInterface1);
+ function("callInterface2", &callInterface2);
+ function("callInterface3", &callInterface3);
}
void __attribute__((noinline)) emscripten_get_now_benchmark(int N)
@@ -435,4 +485,5 @@ int main()
emscripten_get_now();
call_through_interface0();
call_through_interface1();
+ call_through_interface2();
}