Skip to content

Instantly share code, notes, and snippets.

@satyr
Forked from os0x/gist:369663
Created April 17, 2010 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satyr/369771 to your computer and use it in GitHub Desktop.
Save satyr/369771 to your computer and use it in GitHub Desktop.
<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