Last active
August 29, 2015 13:56
-
-
Save shaekuronen/9021131 to your computer and use it in GitHub Desktop.
User Timing API
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> | |
<meta name="description" content="User Timing API" /> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<!-- http://www.html5rocks.com/en/tutorials/webperformance/usertiming/ --> | |
</head> | |
<body> | |
<button id="get-time-button">Get Time</button> | |
<h4 id="current-time-display"></h4> | |
<h4 id="time-since-last-click-display"></h4> | |
</body> | |
</html> |
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
get_time_button = document.getElementById("get-time-button"), | |
current_time_display = document.getElementById("current-time-display"), | |
time_since_last_click_display = document.getElementById("time-since-last-click-display"), | |
current_time = 0; | |
get_time_button.addEventListener("click", function() { | |
// if the current time button has not been clicked | |
if (current_time === 0) { | |
current_time = window.performance.now(); | |
current_time_display.innerHTML = "Milleseconds since <a href='http://www.w3.org/TR/navigation-timing/#dom-performancetiming-navigationstart' target='_blank'>navigationStart</a> is : " + current_time; | |
} else { | |
// create local variable to store previous time | |
var previous_current_time = current_time; | |
current_time = window.performance.now(); | |
current_time_display.innerHTML = "Time since <a href='http://www.w3.org/TR/navigation-timing/#dom-performancetiming-navigationstart' target='_blank'>navigationStart</a> is : " + current_time; | |
time_since_last_click_display.innerHTML = "Milleseconds since Get Time button last clicked: " + (current_time - previous_current_time); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment