1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 var itrSend = new Float64Array(itrMax);
8 var itrNaCl = new Float64Array(itrMax);
9 var itrRecv = new Float64Array(itrMax);
12 function getTimeInMilliseconds() {
13 return (new Date()).getTime();
16 function attachListeners() {
17 document.getElementById('start').addEventListener('click', startTest);
18 countEl = document.getElementById('count');
19 countEl.textContent = itrMax;
22 function startTest() {
23 if (common.naclModule) {
24 var startEl = document.getElementById('start');
25 startEl.disabled = true;
27 var delayEl = document.getElementById('delay');
28 delay = parseInt(delayEl.value, 10);
30 common.updateStatus('Running Test');
32 itrSend[0] = getTimeInMilliseconds();
33 common.naclModule.postMessage(delay);
37 function setStats(nacl, compute, total) {
38 var statNaClEl = document.getElementById('NaCl');
39 var statRoundEl = document.getElementById('Round');
40 var statTotalEl = document.getElementById('Total');
42 statNaClEl.textContent = (nacl / itrMax) + ' ms';
43 statRoundEl.textContent = (compute / itrMax) + ' ms';
44 statTotalEl.textContent = (total / itrMax) + ' ms';
47 // Called by the common.js module.
48 function handleMessage(message_event) {
49 // Convert NaCl Seconds elapsed to MS
50 itrNaCl[itrCount] = message_event.data * 1000.0;
51 itrRecv[itrCount] = getTimeInMilliseconds();
54 if (itrCount === itrMax) {
55 common.updateStatus('Test Finished');
56 var startEl = document.getElementById('start');
57 startEl.disabled = false;
61 for (var i = 0; i < itrMax; i++) {
63 computeMS += itrRecv[i] - itrSend[i];
66 setStats(naclMS, computeMS, itrRecv[itrMax - 1] - itrSend[0]);
68 itrSend[itrCount] = getTimeInMilliseconds();
69 common.naclModule.postMessage(delay);