json-guard-12

Benchmark created on


Setup

var data = {a: 5, b: "asdasdasdasd", c: "sdfuasfdasdf"};
    var json = JSON.stringify([data, data, data, data, data, data, data, data]);
    var u2028 = /\u2028/g,
        u2029 = /\u2029/g;

Test runner

Ready to run.

Testing in
TestOps/sec
replace regex
// no new RegExp and new function per each call
if (-1 < json.indexOf('\u2028')) {
   json = json.replace(u2028, '\\u2028');
}
if (-1 < json.indexOf('\u2029')) {
   json = json.replace(u2029, '\\u2029');
}
ready
no if
// no new RegExp and new function per each call
json = json.replace(u2028, '\\u2028');
json = json.replace(u2029, '\\u2029');
ready
// no new RegExp and new function per each call
json = json.replace('\u2028', '\\u2028');
json = json.replace('\u2029', '\\u2029');
ready

Revisions

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