OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Audio Loop Benchmark</title> |
| 5 <style>* { font-family: monospace; }</style> |
| 6 </head> |
| 7 <body> |
| 8 <h1>Audio Loop Benchmark</h1> |
| 9 <p> |
| 10 Benchmark measuring how fast we can continuously repeat a short sound |
| 11 clip. In the ideal scenario we'd have zero latency processing script, |
| 12 seeking back to the beginning of the clip, and resuming audio playback. |
| 13 </p> |
| 14 |
| 15 <button onclick="startTest();">Start</button> |
| 16 |
| 17 <p> |
| 18 Times Played: <span id="times"></span></span><br> |
| 19 Clip Duration: <span id="clip"></span></span><br> |
| 20 Ideal Duration: <span id="ideal"></span><br> |
| 21 Actual Duration: <span id="actual"></span><br> |
| 22 Average Latency: <span id="average"></span><br> |
| 23 </p> |
| 24 |
| 25 <script> |
| 26 var TIMES = 50, averageLatency = 0; |
| 27 |
| 28 function getAndClearElement(id) { |
| 29 var elem = document.getElementById(id); |
| 30 elem.innerText = ''; |
| 31 return elem; |
| 32 } |
| 33 |
| 34 function startTest() { |
| 35 var timesElem = getAndClearElement('times'); |
| 36 var clipElem = getAndClearElement('clip'); |
| 37 var idealElem = getAndClearElement('ideal'); |
| 38 var actualElem = getAndClearElement('actual'); |
| 39 var averageElem = getAndClearElement('average'); |
| 40 var buttonElem = document.querySelector('button'); |
| 41 |
| 42 var loopCount = 0, idealDuration = 0, actualDuration = 0; |
| 43 var startTime; |
| 44 |
| 45 buttonElem.disabled = true; |
| 46 |
| 47 function onLoaded() { |
| 48 idealDuration = Math.round(audio.duration * TIMES * 1000, 0); |
| 49 idealElem.innerText = idealDuration + ' ms'; |
| 50 clipElem.innerText = Math.round(audio.duration * 1000, 0) + ' ms'; |
| 51 audio.addEventListener('seeked', onLoop); |
| 52 startTime = window.performance.webkitNow(); |
| 53 audio.play(); |
| 54 } |
| 55 |
| 56 var audio = document.createElement('audio'); |
| 57 audio.addEventListener('canplaythrough', onLoaded); |
| 58 audio.loop = true; |
| 59 audio.src = '../pink_noise_140ms.wav'; |
| 60 |
| 61 function onLoop() { |
| 62 ++loopCount; |
| 63 timesElem.innerText = loopCount + '/' + TIMES; |
| 64 if (loopCount == TIMES) { |
| 65 actualDuration = window.performance.webkitNow() - startTime; |
| 66 actualElem.innerText = actualDuration + ' ms'; |
| 67 buttonElem.disabled = false; |
| 68 |
| 69 averageLatency = (actualDuration - idealDuration) / loopCount; |
| 70 averageElem.innerText = averageLatency + ' ms'; |
| 71 |
| 72 // Let the PyAuto test know we're done testing. |
| 73 if (window.domAutomationController) |
| 74 window.domAutomationController.send(true); |
| 75 |
| 76 audio.pause(); |
| 77 } |
| 78 } |
| 79 } |
| 80 </script> |
| 81 </body> |
| 82 </html> |
OLD | NEW |