aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2013-04-21 09:11:57 +0300
committerJukka Jylänki <jujjyl@gmail.com>2013-04-21 09:15:05 +0300
commitfe8c5821fce322bee6d334aa191baf3f3187d527 (patch)
treee00a1bbd287ad27f02b9ab4f2ceb36cdc9be721e
parent6f8af49c568abfb3b4203f1d3dc95e12fe573986 (diff)
Add new passgameobject_ptr embind benchmark to test smartptr routing in and out of functions.
-rw-r--r--tests/embind/embind.benchmark.js23
-rw-r--r--tests/embind/embind_benchmark.cpp29
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/embind/embind.benchmark.js b/tests/embind/embind.benchmark.js
index 4ce9355c..fcbd64ef 100644
--- a/tests/embind/embind.benchmark.js
+++ b/tests/embind/embind.benchmark.js
@@ -195,7 +195,30 @@ function _move_gameobjects_benchmark_embind_js() {
var t = objects[i]['GetTransform']();
accum = Module['add'](Module['add'](accum, t['GetPosition']()), t['GetRotation']());
t['delete']();
+ objects[i]['delete']();
}
Module.print("JS embind move_gameobjects " + N + " iters: " + (b-a) + " msecs. Result: " + (accum[0] + accum[1] + accum[2]));
}
+
+function _pass_gameobject_ptr_benchmark_embind_js() {
+ var N = 100000;
+ var objects = [];
+ for(i = 0; i < N; ++i) {
+ objects.push(Module['create_game_object']());
+ }
+
+ var a = _emscripten_get_now();
+ for(i = 0; i < N; ++i) {
+ var t = Module['pass_gameobject_ptr'](objects[i]);
+ t['delete']();
+ }
+ var b = _emscripten_get_now();
+
+ for(i = 0; i < N; ++i) {
+ objects[i]['delete']();
+ }
+
+ Module.print("JS embind pass_gameobject_ptr " + N + " iters: " + (b-a) + " msecs.");
+}
+
diff --git a/tests/embind/embind_benchmark.cpp b/tests/embind/embind_benchmark.cpp
index 80abc7e7..cdfe998c 100644
--- a/tests/embind/embind_benchmark.cpp
+++ b/tests/embind/embind_benchmark.cpp
@@ -45,6 +45,9 @@ extern void sum_float_benchmark_embind_js();
extern void increment_class_counter_benchmark_embind_js(int N);
extern void move_gameobjects_benchmark_embind_js();
+
+extern void pass_gameobject_ptr_benchmark();
+extern void pass_gameobject_ptr_benchmark_embind_js();
}
class Vec3
@@ -94,6 +97,11 @@ GameObjectPtr create_game_object()
return std::make_shared<GameObject>();
}
+GameObjectPtr __attribute__((noinline)) pass_gameobject_ptr(GameObjectPtr p)
+{
+ return p;
+}
+
class Foo
{
public:
@@ -143,6 +151,7 @@ EMSCRIPTEN_BINDINGS(benchmark)
.element(&Vec3::z);
function("create_game_object", &create_game_object);
+ function("pass_gameobject_ptr", &pass_gameobject_ptr);
function("add", &add);
function("get_counter", &get_counter);
@@ -306,6 +315,23 @@ void __attribute__((noinline)) move_gameobjects_benchmark()
printf("C++ move_gameobjects %d iters: %f msecs. Result: %f\n", N, (t2-t), accum.x+accum.y+accum.z);
}
+void __attribute__((noinline)) pass_gameobject_ptr_benchmark()
+{
+ const int N = 100000;
+ GameObjectPtr objects[N];
+ for(int i = 0; i < N; ++i)
+ objects[i] = create_game_object();
+
+ volatile float t = emscripten_get_now();
+ for(int i = 0; i < N; ++i)
+ {
+ objects[i] = pass_gameobject_ptr(objects[i]);
+ }
+ volatile float t2 = emscripten_get_now();
+
+ printf("C++ pass_gameobject_ptr %d iters: %f msecs.\n", N, (t2-t));
+}
+
int main()
{
for(int i = 1000; i <= 100000; i *= 10)
@@ -341,4 +367,7 @@ int main()
printf("\n");
move_gameobjects_benchmark();
move_gameobjects_benchmark_embind_js();
+ printf("\n");
+ pass_gameobject_ptr_benchmark();
+ pass_gameobject_ptr_benchmark_embind_js();
}