Skip to content

Instantly share code, notes, and snippets.

@dead-horse
Created September 11, 2014 01:47
Show Gist options
  • Save dead-horse/e638c05babbd224163e4 to your computer and use it in GitHub Desktop.
Save dead-horse/e638c05babbd224163e4 to your computer and use it in GitHub Desktop.
function test(path) {
return path.split('/').join('/');
}
var path1 = 'first';
var path2 = 'second';
var longPath = '.././home//Users/name/git/project/lib/abc/def/zzz.js';
var plusPath = path1 + '/' + path2 + '/' + longPath;
var constantPath = 'first/second/.././home//Users/name/git/project/lib/abc/def/zzz.js';
var length = 1000000;
console.time('plusPath');
for (var i = 0; i < length; i++) {
test(plusPath);
}
console.timeEnd('plusPath');
console.time('constantPath');
for (var i = 0; i < length; i++) {
test(constantPath);
}
console.timeEnd('constantPath');
@fengmk2
Copy link

fengmk2 commented Sep 11, 2014

plusPath: 1016ms
constantPath: 203ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment