C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
And: We call performance.now once before, and once after, the code we wish to benchmark.
Result: We compute the elapsed time and display it in the title bar of the web browser (which is often a tab bar).
JavaScript program that uses performance.now
// The performance.now method measures time in milliseconds.
var time1 = performance.now();
// Perform the benchmark.
for (var i = 0; i < 100000; i++) {
var test = document.createElement("span");
test.id = "test";
}
// Get end time and compute elapsed milliseconds.
var time2 = performance.now();
var elapsed = time2 - time1;
// Write elapsed time to browser title bar.
document.title = elapsed + " ms";
Output
43.48 ms