aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2013-04-11 14:07:23 +0300
committerJukka Jylänki <jujjyl@gmail.com>2013-04-18 20:08:20 +0300
commit75881fce897a3c5849c139866fe46d39d6b05bcd (patch)
treed38d276cb77d5bdd561f71978137664b358a64be
parenta76d9ceaee0a83c0af562753ad5efd01858c1c8b (diff)
Added benchmark for embind code.
-rw-r--r--tests/embind/embind.benchmark.js153
-rw-r--r--tests/embind/embind_benchmark.cpp186
-rw-r--r--tests/embind/shell.html94
3 files changed, 433 insertions, 0 deletions
diff --git a/tests/embind/embind.benchmark.js b/tests/embind/embind.benchmark.js
new file mode 100644
index 00000000..7b08be5d
--- /dev/null
+++ b/tests/embind/embind.benchmark.js
@@ -0,0 +1,153 @@
+function _increment_counter_benchmark_js(N) {
+ var ctr = _get_counter();
+ var a = _emscripten_get_now();
+ for(i = 0; i < N; ++i) {
+ _increment_counter();
+ _increment_counter();
+ _increment_counter();
+ _increment_counter();
+ _increment_counter();
+ _increment_counter();
+ _increment_counter();
+ _increment_counter();
+ _increment_counter();
+ _increment_counter();
+ }
+ var b = _emscripten_get_now();
+ var ctr2 = _get_counter();
+ Module.print("JS increment_counter " + N + " iters: " + (b-a)*1000 + " msecs. result: " + (ctr2-ctr));
+}
+
+function _returns_input_benchmark_js() {
+ var a = _emscripten_get_now();
+ var t = 0;
+ for(i = 0; i < 100000; ++i) {
+ t += _returns_input(i);
+ t += _returns_input(i);
+ t += _returns_input(i);
+ t += _returns_input(i);
+ t += _returns_input(i);
+ t += _returns_input(i);
+ t += _returns_input(i);
+ t += _returns_input(i);
+ t += _returns_input(i);
+ t += _returns_input(i);
+ }
+ var b = _emscripten_get_now();
+ Module.print("JS returns_input 100000 iters: " + (b-a)*1000 + " msecs. result: " + t);
+}
+
+function _sum_int_benchmark_js() {
+ var a = _emscripten_get_now();
+ var r = 0;
+ for(i = 0; i < 100000; ++i) {
+ r += _sum_int(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_int(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_int(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_int(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_int(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_int(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_int(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_int(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_int(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_int(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ }
+ var b = _emscripten_get_now();
+ Module.print("JS sum_int 100000 iters: " + (b-a)*1000 + " msecs. result: " + r);
+}
+
+function _sum_float_benchmark_js() {
+ var a = _emscripten_get_now();
+ var r = 0;
+ for(i = 0; i < 100000; ++i) {
+ r += _sum_float(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_float(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_float(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_float(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_float(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_float(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_float(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_float(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_float(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += _sum_float(i, 2, 3, 4, 5, 6, 7, 8, 9);
+ }
+ var b = _emscripten_get_now();
+ Module.print("JS sum_float 100000 iters: " + (b-a)*1000 + " msecs. result: " + r);
+}
+
+function _increment_counter_benchmark_embind_js(N) {
+ var ctr = _get_counter();
+ var a = _emscripten_get_now();
+ for(i = 0; i < N; ++i) {
+ Module['increment_counter']();
+ Module['increment_counter']();
+ Module['increment_counter']();
+ Module['increment_counter']();
+ Module['increment_counter']();
+ Module['increment_counter']();
+ Module['increment_counter']();
+ Module['increment_counter']();
+ Module['increment_counter']();
+ Module['increment_counter']();
+ }
+ var b = _emscripten_get_now();
+ var ctr2 = _get_counter();
+ Module.print("JS embind increment_counter " + N + " iters: " + (b-a)*1000 + " msecs. result: " + (ctr2-ctr));
+}
+
+function _returns_input_benchmark_embind_js() {
+ var a = _emscripten_get_now();
+ var t = 0;
+ for(i = 0; i < 100000; ++i) {
+ t += Module['returns_input'](i);
+ t += Module['returns_input'](i);
+ t += Module['returns_input'](i);
+ t += Module['returns_input'](i);
+ t += Module['returns_input'](i);
+ t += Module['returns_input'](i);
+ t += Module['returns_input'](i);
+ t += Module['returns_input'](i);
+ t += Module['returns_input'](i);
+ t += Module['returns_input'](i);
+ }
+ var b = _emscripten_get_now();
+ Module.print("JS embind returns_input 100000 iters: " + (b-a)*1000 + " msecs. result: " + t);
+}
+
+function _sum_int_benchmark_embind_js() {
+ var a = _emscripten_get_now();
+ var r = 0;
+ for(i = 0; i < 100000; ++i) {
+ r += Module['sum_int'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_int'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_int'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_int'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_int'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_int'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_int'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_int'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_int'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_int'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ }
+ var b = _emscripten_get_now();
+ Module.print("JS embind sum_int 100000 iters: " + (b-a)*1000 + " msecs. result: " + r);
+}
+
+function _sum_float_benchmark_embind_js() {
+ var a = _emscripten_get_now();
+ var r = 0;
+ for(i = 0; i < 100000; ++i) {
+ r += Module['sum_float'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_float'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_float'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_float'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_float'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_float'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_float'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_float'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_float'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ r += Module['sum_float'](i, 2, 3, 4, 5, 6, 7, 8, 9);
+ }
+ var b = _emscripten_get_now();
+ Module.print("JS embind sum_float 100000 iters: " + (b-a)*1000 + " msecs. result: " + r);
+}
diff --git a/tests/embind/embind_benchmark.cpp b/tests/embind/embind_benchmark.cpp
new file mode 100644
index 00000000..c9391a29
--- /dev/null
+++ b/tests/embind/embind_benchmark.cpp
@@ -0,0 +1,186 @@
+#include <stdio.h>
+#include <emscripten.h>
+#include <bind.h>
+
+int counter = 0;
+
+extern "C"
+{
+
+int __attribute__((noinline)) get_counter()
+{
+ return counter;
+}
+
+void __attribute__((noinline)) increment_counter()
+{
+ ++counter;
+}
+
+int __attribute__((noinline)) sum_int(int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8, int v9)
+{
+ return v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9;
+}
+
+float __attribute__((noinline)) sum_float(float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8, float v9)
+{
+ return v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9;
+}
+
+int __attribute__((noinline)) returns_input(int i)
+{
+ return i;
+}
+
+extern void increment_counter_benchmark_js(int N);
+extern void returns_input_benchmark_js();
+extern void sum_int_benchmark_js();
+extern void sum_float_benchmark_js();
+
+extern void increment_counter_benchmark_embind_js(int N);
+extern void returns_input_benchmark_embind_js();
+extern void sum_int_benchmark_embind_js();
+extern void sum_float_benchmark_embind_js();
+
+}
+
+EMSCRIPTEN_BINDINGS(benchmark)
+{
+ using namespace emscripten;
+
+ function("get_counter", &get_counter);
+ function("increment_counter", &increment_counter);
+ function("returns_input", &returns_input);
+ function("sum_int", &sum_int);
+ function("sum_float", &sum_float);
+}
+
+void __attribute__((noinline)) emscripten_get_now_benchmark(int N)
+{
+ volatile float t = emscripten_get_now();
+ for(int i = 0; i < N; ++i)
+ {
+ emscripten_get_now();
+ emscripten_get_now();
+ emscripten_get_now();
+ emscripten_get_now();
+ emscripten_get_now();
+ emscripten_get_now();
+ emscripten_get_now();
+ emscripten_get_now();
+ emscripten_get_now();
+ emscripten_get_now();
+ }
+ volatile float t2 = emscripten_get_now();
+ printf("C++ emscripten_get_now %d iters: %f msecs.\n", N, 1000.f*(t2-t));
+}
+
+void __attribute__((noinline)) increment_counter_benchmark(int N)
+{
+ volatile float t = emscripten_get_now();
+ for(int i = 0; i < N; ++i)
+ {
+ increment_counter();
+ increment_counter();
+ increment_counter();
+ increment_counter();
+ increment_counter();
+ increment_counter();
+ increment_counter();
+ increment_counter();
+ increment_counter();
+ increment_counter();
+ }
+ volatile float t2 = emscripten_get_now();
+ printf("C++ increment_counter %d iters: %f msecs.\n", N, 1000.f*(t2-t));
+}
+
+void __attribute__((noinline)) returns_input_benchmark()
+{
+ volatile int r = 0;
+ volatile float t = emscripten_get_now();
+ for(int i = 0; i < 100000; ++i)
+ {
+ r += returns_input(i);
+ r += returns_input(i);
+ r += returns_input(i);
+ r += returns_input(i);
+ r += returns_input(i);
+ r += returns_input(i);
+ r += returns_input(i);
+ r += returns_input(i);
+ r += returns_input(i);
+ r += returns_input(i);
+ }
+ volatile float t2 = emscripten_get_now();
+ printf("C++ returns_input 100000 iters: %f msecs.\n", 1000.f*(t2-t));
+}
+
+void __attribute__((noinline)) sum_int_benchmark()
+{
+ volatile float t = emscripten_get_now();
+ volatile int r = 0;
+ for(int i = 0; i < 100000; ++i)
+ {
+ r += sum_int(i,2,3,4,5,6,7,8,9);
+ r += sum_int(i,2,3,4,5,6,7,8,9);
+ r += sum_int(i,2,3,4,5,6,7,8,9);
+ r += sum_int(i,2,3,4,5,6,7,8,9);
+ r += sum_int(i,2,3,4,5,6,7,8,9);
+ r += sum_int(i,2,3,4,5,6,7,8,9);
+ r += sum_int(i,2,3,4,5,6,7,8,9);
+ r += sum_int(i,2,3,4,5,6,7,8,9);
+ r += sum_int(i,2,3,4,5,6,7,8,9);
+ r += sum_int(i,2,3,4,5,6,7,8,9);
+ }
+ volatile float t2 = emscripten_get_now();
+ printf("C++ sum_int 100000 iters: %f msecs.\n", 1000.f*(t2-t));
+}
+
+void __attribute__((noinline)) sum_float_benchmark()
+{
+ volatile float f = 0.f;
+ volatile float t = emscripten_get_now();
+ for(int i = 0; i < 100000; ++i)
+ {
+ f += sum_float((float)i,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f);
+ f += sum_float((float)i,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f);
+ f += sum_float((float)i,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f);
+ f += sum_float((float)i,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f);
+ f += sum_float((float)i,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f);
+ f += sum_float((float)i,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f);
+ f += sum_float((float)i,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f);
+ f += sum_float((float)i,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f);
+ f += sum_float((float)i,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f);
+ f += sum_float((float)i,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f);
+ }
+ volatile float t2 = emscripten_get_now();
+ printf("C++ sum_float 100000 iters: %f msecs.\n", 1000.f*(t2-t));
+}
+
+int main()
+{
+ for(int i = 1000; i <= 100000; i *= 10)
+ emscripten_get_now_benchmark(i);
+
+ printf("\n");
+ for(int i = 1000; i <= 100000; i *= 10)
+ {
+ increment_counter_benchmark(i);
+ increment_counter_benchmark_js(i);
+ increment_counter_benchmark_embind_js(i);
+ printf("\n");
+ }
+
+ returns_input_benchmark();
+ returns_input_benchmark_js();
+ returns_input_benchmark_embind_js();
+ printf("\n");
+ sum_int_benchmark();
+ sum_int_benchmark_js();
+ sum_int_benchmark_embind_js();
+ printf("\n");
+ sum_float_benchmark();
+ sum_float_benchmark_js();
+ sum_float_benchmark_embind_js();
+}
diff --git a/tests/embind/shell.html b/tests/embind/shell.html
new file mode 100644
index 00000000..6664ec78
--- /dev/null
+++ b/tests/embind/shell.html
@@ -0,0 +1,94 @@
+<!doctype html>
+<html lang="en-us">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>Emscripten-Generated Code</title>
+ <style>
+ .emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
+ textarea.emscripten { font-family: monospace; width: 80%; }
+ div.emscripten { text-align: center; }
+ div.emscripten_border { border: 1px solid black; }
+ /* the canvas *must not* have any border or padding, or mouse coords will be wrong */
+ canvas.emscripten { border: 0px none; }
+ </style>
+ </head>
+ <body>
+ <div class="emscripten" id="status">Downloading...</div>
+ <div class="emscripten">
+ <progress value="0" max="100" id="progress" hidden=1></progress>
+ </div>
+ <div class="emscripten_border" style="display:none;">
+ <canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
+ </div>
+ <div class="emscripten" style="display:none;">
+ <input type="checkbox" id="resize">Resize canvas
+ <input type="checkbox" id="pointerLock" checked>Lock/hide mouse pointer
+ &nbsp;&nbsp;&nbsp;
+ <input type="button" value="Fullscreen" onclick="Module.requestFullScreen(document.getElementById('pointerLock').checked,
+ document.getElementById('resize').checked)">
+ </div>
+
+ <hr/>
+ <textarea class="emscripten" id="output" rows="45"></textarea>
+ <hr>
+ <script type='text/javascript'>
+ // connect to canvas
+ var Module = {
+ preRun: [],
+ postRun: [],
+ print: (function() {
+ var element = document.getElementById('output');
+ element.value = ''; // clear browser cache
+ return function(text) {
+ text = Array.prototype.slice.call(arguments).join(' ');
+ // These replacements are necessary if you render to raw HTML
+ //text = text.replace(/&/g, "&amp;");
+ //text = text.replace(/</g, "&lt;");
+ //text = text.replace(/>/g, "&gt;");
+ //text = text.replace('\n', '<br>', 'g');
+ element.value += text + "\n";
+ element.scrollTop = 99999; // focus on bottom
+ };
+ })(),
+ printErr: function(text) {
+ text = Array.prototype.slice.call(arguments).join(' ');
+ if (0) { // XXX disabled for safety typeof dump == 'function') {
+ dump(text + '\n'); // fast, straight to the real console
+ } else {
+ console.log(text);
+ }
+ },
+ canvas: document.getElementById('canvas'),
+ setStatus: function(text) {
+ if (Module.setStatus.interval) clearInterval(Module.setStatus.interval);
+ var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
+ var statusElement = document.getElementById('status');
+ var progressElement = document.getElementById('progress');
+ if (m) {
+ text = m[1];
+ progressElement.value = parseInt(m[2])*100;
+ progressElement.max = parseInt(m[4])*100;
+ progressElement.hidden = false;
+ } else {
+ progressElement.value = null;
+ progressElement.max = null;
+ progressElement.hidden = true;
+ }
+ statusElement.innerHTML = text;
+ },
+ totalDependencies: 0,
+ monitorRunDependencies: function(left) {
+ this.totalDependencies = Math.max(this.totalDependencies, left);
+ Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
+ }
+ };
+ Module.setStatus('Downloading...');
+ </script>
+ <script type='text/javascript'>
+
+ {{{ SCRIPT_CODE }}}
+
+ </script>
+ </body>
+</html>