variable data types

Benchmark created by naugtur on


Description

Ilustrating how changing the type of content of a variable breaks JIT

Preparation HTML

<script>
  function correct(){
  var a=123,b='zzz';
  if(Math.random()>0.5){
   b='zzzz';
   }else{
   a=1234;
   }
  a+=123456789;
  b+='123456789';
  }
  
  function bad(){
  var a=123,b='zzz';
  if(Math.random()>0.5){
   a='zzzz'; //swapped
   }else{
   b=1234; //swapped
   }
  a+=123456789;
  b+='123456789';
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
correct
correct()
ready
bad
bad()
ready

Revisions

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

  • Revision 1: published by naugtur on
  • Revision 2: published by naugtur on