Created
November 28, 2013 03:02
-
-
Save pwnall/7686669 to your computer and use it in GitHub Desktop.
Experiment that measures the drift between the V8 clock and the Blink clock.
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> | |
<script> | |
// Maximum difference between Blink's clock and V8's. | |
var maxDelta = 0; | |
// Measure clock differences for 30 seconds. | |
// | |
// Browsers will stop our JavaScript if it runs for too long without returning | |
// control to the event loop. | |
var smallTest = function() { | |
var startTime = Date.now(); | |
var oldNow = startTime; | |
while (true) { | |
var blinkTime = (new File([], 'x.txt')).lastModifiedDate.valueOf(); | |
var v8Time = Date.now(); | |
var clocksDelta = Math.abs(blinkTime - v8Time); | |
if (maxDelta < clocksDelta) { | |
maxDelta = clocksDelta; | |
console.log("maxDelta increased to " + maxDelta); | |
} | |
if (v8Time - startTime > 30 * 1000) { | |
break; // Stop after 30 seconds. | |
} | |
} | |
}; | |
// Call smallTest() 10 times, with 30-second breaks in between. | |
// | |
// This means the test will run for 10 minutes. | |
var largeTest = function() { | |
var runsLeft = 10; | |
var oneRun = function () { | |
smallTest(); | |
runsLeft -= 1; | |
if (runsLeft === 0) { | |
console.log("Done"); | |
return; | |
} | |
setTimeout(oneRun, 10); | |
}; | |
oneRun(); | |
}; | |
largeTest(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment