Easy (To Read) Does It

JavaScript performance comparison

Test case created by LilaHickey

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  let responseObject = {};
  if(Math.random() < 0.5){
     responseObject = {
        filepath: ['http://ip/logfiles/file.tar'],
        file: 'file.tar'
     }
  } else {
     responseObject = {
        file: 'file.tar'
     }
  }

};
</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
Option #1 (String Interpolation)
string = 'http://ip/logfiles/'+responseObject.file;
pending…
Option #2 (If/Else w/ Optimal Conditional)
if(!!responseObject.filepath && responseObject.filepath.length>0) {
   string = responseObject.filepath[0];
} else {
   string = 'http://ip/logfiles/'+responseObject.file;
}
pending…
Option #3 (If/Else w/ Expensive Conditional)
if(!!responseObject.hasOwnProperty('filepath') && responseObject.filepath.length>0) {
   string = responseObject.filepath[0];
} else {
   string = 'http://ip/logfiles/'+responseObject.file;
}
pending…

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

0 Comments