variable data types (v2)

Revision 2 of this 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';
   a=1234;
   }else{
   b='zzzz';
   a=1234;
   }
  
  b='zzzz';
  a=1234;
  a+=123456789;
  b+='123456789';
  }
  
  function bad(){
  var a=123,b='zzz';
  if(Math.random()>0.5){
   a='zzzz'; //messing types at random
   b=1234;
   }else{
   b='zzzz';
   a=1234;
   }
  b='zzzz';
  a=1234;
  b+=123456789;
  a+='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