Last active
September 25, 2017 22:15
-
-
Save nolanlawson/ee7433f622577872d2e264d04ba2b833 to your computer and use it in GitHub Desktop.
Audio benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Audio benchmark</title> | |
</head> | |
<body> | |
<h1>Audio benchmark</h1> | |
<button type='button'>Click me to play a sound</button> | |
<pre></pre> | |
<script> | |
// preload audio | |
let preloaded = new Audio('boop.mp3') | |
preloaded.volume = 0 | |
preloaded.play() | |
document.querySelector('button').addEventListener('click', () => { | |
performance.clearMarks() | |
performance.clearMeasures() | |
performance.mark('create:audio') | |
let audio = new Audio('boop.mp3') | |
performance.mark('play:audio') | |
audio.play() | |
performance.mark('end:audio') | |
performance.measure('audio', 'create:audio', 'end:audio') | |
document.querySelector('pre').innerHTML += 'Duration: ' + performance.getEntriesByType('measure').slice(-1)[0].duration + 'ms\n' | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment