Index: chrome/test/data/media/html/audio_latency_perf.html |
diff --git a/chrome/test/data/media/html/audio_latency_perf.html b/chrome/test/data/media/html/audio_latency_perf.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5f22ab22e1fbbb2bde98e836363b86d82bff2748 |
--- /dev/null |
+++ b/chrome/test/data/media/html/audio_latency_perf.html |
@@ -0,0 +1,82 @@ |
+<!DOCTYPE html> |
+<html> |
+ <head> |
+ <title>Audio Loop Benchmark</title> |
+ <style>* { font-family: monospace; }</style> |
+ </head> |
+ <body> |
+ <h1>Audio Loop Benchmark</h1> |
+ <p> |
+ Benchmark measuring how fast we can continuously repeat a short sound |
+ clip. In the ideal scenario we'd have zero latency processing script, |
+ seeking back to the beginning of the clip, and resuming audio playback. |
+ </p> |
+ |
+ <button onclick="startTest();">Start</button> |
+ |
+ <p> |
+ Times Played: <span id="times"></span></span><br> |
+ Clip Duration: <span id="clip"></span></span><br> |
+ Ideal Duration: <span id="ideal"></span><br> |
+ Actual Duration: <span id="actual"></span><br> |
+ Average Latency: <span id="average"></span><br> |
+ </p> |
+ |
+ <script> |
+ var TIMES = 50, averageLatency = 0; |
+ |
+ function getAndClearElement(id) { |
+ var elem = document.getElementById(id); |
+ elem.innerText = ''; |
+ return elem; |
+ } |
+ |
+ function startTest() { |
+ var timesElem = getAndClearElement('times'); |
+ var clipElem = getAndClearElement('clip'); |
+ var idealElem = getAndClearElement('ideal'); |
+ var actualElem = getAndClearElement('actual'); |
+ var averageElem = getAndClearElement('average'); |
+ var buttonElem = document.querySelector('button'); |
+ |
+ var loopCount = 0, idealDuration = 0, actualDuration = 0; |
+ var startTime; |
+ |
+ buttonElem.disabled = true; |
+ |
+ function onLoaded() { |
+ idealDuration = Math.round(audio.duration * TIMES * 1000, 0); |
+ idealElem.innerText = idealDuration + ' ms'; |
+ clipElem.innerText = Math.round(audio.duration * 1000, 0) + ' ms'; |
+ audio.addEventListener('seeked', onLoop); |
+ startTime = window.performance.webkitNow(); |
+ audio.play(); |
+ } |
+ |
+ var audio = document.createElement('audio'); |
+ audio.addEventListener('canplaythrough', onLoaded); |
+ audio.loop = true; |
+ audio.src = '../pink_noise_140ms.wav'; |
+ |
+ function onLoop() { |
+ ++loopCount; |
+ timesElem.innerText = loopCount + '/' + TIMES; |
+ if (loopCount == TIMES) { |
+ actualDuration =window.performance.webkitNow(); - startTime; |
shadi
2012/05/21 22:59:44
Is the semi-colon intentional?
Plus, does this wo
DaleCurtis
2012/05/21 23:02:56
Whoops, typos galore! It does work w/o PyAuto, it'
|
+ actualElem.innerText = actualDuration + ' ms'; |
+ buttonElem.disabled = false; |
+ |
+ averageLatency = (actualDuration - idealDuration) / loopCount; |
+ averageElem.innerText = averageLatency + ' ms'; |
+ |
+ // Let the PyAuto test know we're done testing. |
+ if (window.domAutomationController) |
+ window.domAutomationController.send(true); |
+ |
+ audio.pause(); |
+ } |
+ } |
+ } |
+ </script> |
+ </body> |
+</html> |