Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: native_client_sdk/src/examples/benchmarks/example.js

Issue 664543003: Benchmark sample for SDK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/examples/benchmarks/example.js
diff --git a/native_client_sdk/src/examples/benchmarks/example.js b/native_client_sdk/src/examples/benchmarks/example.js
new file mode 100644
index 0000000000000000000000000000000000000000..74737bebefea5af58c6177eddd09a10915fb6d58
--- /dev/null
+++ b/native_client_sdk/src/examples/benchmarks/example.js
@@ -0,0 +1,41 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function moduleDidLoad() {
+}
+
+
+// Add event listeners after the NaCl module has loaded. These listeners will
+// forward messages to the NaCl module via postMessage()
+function attachListeners() {
+ setTimeout(function() { common.updateStatus('READY TO RUN'); }, 200);
+ document.getElementById('benchmark').addEventListener('click',
+ function() {
+ common.naclModule.postMessage({'message' : 'run_benchmark'});
+ common.updateStatus('BENCHMARKING... (please wait)');
+ var window = document.getElementById('result').contentWindow;
+ window.document.writeln('<samp>Starting Benchmark Suite<br>');
+ window.document.writeln('<table>');
+ });
+}
+
+
+// Handle a message coming from the NaCl module.
+function handleMessage(message_event) {
+ if (message_event.data.message == 'benchmark_result') {
+ // benchmark result
+ var name = message_event.data.benchmark.name;
+ var result = message_event.data.benchmark.result;
+ var text = '<tr><th>' + name + ': </th><th>' + result + '</th></tr>';
+ console.log(text);
+ var window = document.getElementById('result').contentWindow;
+ window.document.writeln(text);
+ }
+ if (message_event.data.message == 'benchmark_finish') {
+ common.updateStatus('READY TO RUN');
+ var window = document.getElementById('result').contentWindow;
+ window.document.writeln('</table>');
+ window.document.writeln('Finished.<br><br></samp>');
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698