test string manipulation

Benchmark created by canon on


Setup

var array = [
          "lat: 0, lng: 0;",
          "lat: 26.340541, lng: -80.24478;",
          "lat: 26.771140611497685, lng: -80.5530115950387;",
          "lat: 26.965012847445905, lng: -80.31122515234165;",
          "lat: 26.530756378779188, lng: -80.44429887994193;",
          "lat: 26.697621166240424, lng: -80.14912072988227;",
          "lat: 26.6251646541059, lng: -80.54218244669028;",
          "lat: 26.59252144373022, lng: -80.17727145808749;",
          "lat: 26.18519592867233, lng: -80.13126336899586;",
          "lat: 26.598507820395753, lng: -80.90967331570573;",
          "lat: 26.47811984992586, lng: -80.73396600456908;",
          "lat: 26.484661074355245, lng: -80.43525952659547;"
        ];

Test runner

Ready to run.

Testing in
TestOps/sec
original
array.map(function(str) {
  return JSON.parse("{" + str.substring(0, str.length - 1).replace(/lat/, '"lat"').replace(/lng/, '"lng"') + "}")
});
ready
tweaked
array.map(function(str) {
  return JSON.parse('{'+str.slice(0,-1).replace(/lat|lng/g,'"$&"')+'}')
});
ready

Revisions

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