-
-
Save satyr/369771 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 run(fn, arg){ | |
var start = new Date; | |
for(var i = 1e4; i--;) fn(arg); | |
return new Date - start; | |
} | |
var tests = [function(src){ | |
return src.slice(0, src.lastIndexOf("/") + 1); | |
}, function(src){ | |
var a = src.split("/"); | |
a.pop(); | |
return a.join("/") + "/"; | |
}, function(src){ | |
return src.split("/").slice(0, -1).join("/") + "/"; | |
}, function(src){ | |
return /^.+\//.exec(src)[0]; | |
}, function(src){ | |
return src.replace(/[^/]+$/, ""); | |
}]; | |
var src = "http://example.com/lab/test.js"; | |
for(var t, i = -1; t = tests[++i];){ | |
if(t(src) !== "http://example.com/lab/") throw t; | |
tests[i] += " -> " + run(t, src); | |
} | |
document.write("<pre>" + tests.join("\n\n")); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment