if/substring (v2)

Revision 2 of this benchmark created on


Setup

var data = {"a":"one", "b":"two", "c":"three", "d":"four", "e":"five"};
    
    var postString = "";
    
    var key;

Test runner

Ready to run.

Testing in
TestOps/sec
if
postString = "";
for (key in data) {
    if(postString !== "") {
        postString += "&";
    }
    postString += key + "=" + data[key];
}
ready
substring
postString = "";
for (key in data) {
    postString += "&" + key + "=" + data[key];
}
postString = postString.substring(1);
ready
join
postString = [];
for (key in data) {
    postString.push(key + "=" + data[key]);
}
postString = postString.join("&");
ready
final char slice
postString = "";
for (key in data) {
    postString += key + "=" + data[key] + "&";
}
postString = postString.slice(0, -1);
ready
first char slice
postString = "";
for (key in data) {
    postString += "&" + key + "=" + data[key];
}
postString = postString.slice(1);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.