Longitude normalisation

JavaScript performance comparison

Test case created by yjo

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const lons = Array.from({length: 10000}, () => Math.random() * 1440 - 720);

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
loops
function normalise_loop(lon) {
  while(lon < -180){
    lon +=360;
  }
  while (lon > 180){
    lon -= 360;
  }
  return lon;
}
lons.map(normalise_loop);
pending…
modulo
function normalise_mod(lon) {
  return (lon % 360 + 540) % 360 - 180;
}
lons.map(normalise_mod);
pending…

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

Compare results of other browsers

0 Comments