Created
April 11, 2016 18:38
-
-
Save bmizerany/f094aa92dd121afd304bb0f3b2b06ee3 to your computer and use it in GitHub Desktop.
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
<script> | |
function ready() { | |
function benchmark(n, f) { | |
var sum = 0.0; | |
var total = n; | |
while (n--) { | |
var u = 'https://google.com?q=1' + Math.random().toString(36).substring(7); | |
var s = performance.now(); | |
f(u); | |
var e = performance.now(); | |
sum += (e - s); | |
} | |
var avg = sum / total; | |
document.write("<div>"+avg+"</div>"); | |
} | |
var n = 10.0; | |
setTimeout(function() { | |
var a = document.createElement('a'); | |
benchmark(n, function(u) { | |
a.href = u; | |
var h = a.hostname; | |
}) | |
}, 1000); | |
setTimeout(function() { | |
var b = /^(?:\w+\:\/\/)?([^\/]+)(.*)$/; | |
benchmark(n, function(u) {; | |
var x = b.exec(u); | |
var h = x[1].split('?')[0]; | |
}); | |
}, 1000); | |
} | |
document.addEventListener("DOMContentLoaded", ready); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment