if -swicth

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
if
arg = [{"x": 2.0, "y": 3.0}, {"x": 2.5, "y": 3.5}, {"x": 5.0, "y": 3.0}, {"x": -2.0, "y": -3.0}, {"x": -2.0, "y": 3.0}, {"x": 2.0, "y": -3.0}]
var sections = [99, 99, 99, 99, 99]
  for (i=0; i<arg.length; i++){
    let d = Math.sqrt(Math.pow(arg[i].x, 2)+ Math.pow(arg[i].y, 2));
    let alpha = -1; 
    if(d<5){
      alpha = Math.sin(arg[i].y/d);
    }
    else if(d<10){
      alpha = Math.sin(arg[i].y/d);
    }
    switch(true){
      case alpha > -Math.PI/8 && alpha < Math.PI/8 :
        if (arg[i].x < 0) sections[4] = d;
        else sections[0] = d;
        break;
      case (alpha > Math.PI/8 && alpha < 2*Math.PI/8 ):
        if (arg[i].x < 0) sections[3] = d;
        else sections[1] = d;  
        break;
      case (alpha == -1):
        break;
      default: 
        sections[2] = d;
        break;
    }
  }
  console.log(sections);
ready
switch
arg = [{"x": 2.0, "y": 3.0}, {"x": 2.5, "y": 3.5}, {"x": 5.0, "y": 3.0}, {"x": -2.0, "y": -3.0}, {"x": -2.0, "y": 3.0}, {"x": 2.0, "y": -3.0}]
var sections = [99, 99, 99, 99, 99]
  for (i=0; i<arg.length; i++){
    let d = Math.sqrt(Math.pow(arg[i].x, 2)+ Math.pow(arg[i].y, 2));
    let alpha = -1; 
    if(d<5){
      alpha = Math.sin(arg[i].y/d);
    }
    else if(d<10){
      alpha = Math.sin(arg[i].y/d);
    }
    switch(true){
      case alpha > -Math.PI/8 && alpha < Math.PI/8 :
        if (arg[i].x < 0) sections[4] = d;
        else sections[0] = d;
        break;
      case (alpha > Math.PI/8 && alpha < 2*Math.PI/8 ):
        if (arg[i].x < 0) sections[3] = d;
        else sections[1] = d;  
        break;
      case (alpha == -1):
        break;
      default: 
        sections[2] = d;
        break;
    }
  }
  console.log(sections);
ready

Revisions

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