Created
August 11, 2017 13:24
-
-
Save JochemKuijpers/86217cec7c860c0af0dfc06bbddacc42 to your computer and use it in GitHub Desktop.
Javascript date timer demo
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
<html> | |
<head> | |
<title>Javascript date timer demo</title> | |
<script type="text/javascript"> | |
var e; | |
function init() { | |
e = document.getElementById("pre"); | |
} | |
function hangButton() { | |
for (var a = 0; a < 2e9; a += 1) {} | |
} | |
function genButton() { | |
e.innerHTML += '\nrand' + new Date().getTime(); | |
} | |
</script> | |
</head> | |
<body onload="init()"> | |
<p> | |
1. <button onclick="hangButton()">Hang browser</button> | |
</p> | |
<p> | |
2. While the browser hangs for a bit, spam the button below | |
</p> | |
<p> | |
3. <button onclick="genButton()">Generate IDs</button> | |
</p> | |
<hr> | |
<p>Generated IDs:</p> | |
<pre id="pre"></pre> | |
<!-- | |
Firefox test: | |
rand1502457751992 | |
rand1502457751996 | |
rand1502457751999 | |
rand1502457752003 | |
(average of 3~4 apart, still too close for comfort as faster devices will close that gap) | |
Chrome test: | |
rand1502457699211 | |
rand1502457699211 | |
rand1502457699212 | |
rand1502457699212 | |
rand1502457699212 | |
(identical IDs, chrome apparently has a faster javascript engine (?)) | |
--> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment