Sunday, January 5, 2014

jsPerf tests for split join replace

Today I have found this code in connect middleware:
exports.normalizeSlashes = function normalizeSlashes(path) {
return path.split(sep).join('/');
};
So I have immediately jumped to jsPerf and wanted to compare this to alternative methods (for speed).
Unlucky as always, I have run into several nonsense tests:

http://jsperf.com/split-join-vs-replace-47 - Both revisions 1,2 are wrong not comparing the same things

http://jsperf.com/regexp-vs-split-join2 - another treasure

and we could you with the list.
Again and again, broken tests and misleading measurements.
Please all of you who run into this article, and write or use jsPerf results
please read using-jsperf-correctly.

BTW: there is enough room for fiddling elsewhere. On of the tips: "http://jsfiddle.net"