String compare VS number compare (v8)

Revision 8 of this benchmark created by d on


Description

What is faster? Comparing a number or comparing a string?

Preparation HTML

<script>
  var a1 = '12345678',
      a2  = '87654321',
      a3 = '12345678';

  var b1  = '12345678123456781234567812345678123456781234567812345678',
      b2  = '87654321876543218765432187654321876543218765432187654321',
      b3  = '12345678123456781234567812345678123456781234567812345678';

  var c1 = 0xFFFFFFFFAACCFF00,
      c2 = 0xFFFFFFFFFFFF0001,
      c3 = 0xFFFFFFFFAACCFF00;

  var d1 = 1.524198274617236125290185273,
      d2 = 1.524198274617232125290185273,
      d3 = 1.524198274617236125290185273;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Short String
a1 == a2
ready
Long String
b1 == b2
ready
uint
c1 == c2
ready
float
d1 == d2
ready
string short equal
a1 === a3
ready
string long equal
b1 === b3
ready
uint equal
c1 === c3
ready
float equal
d1 === d3
ready
switch string
switch ('asdf') {
  case a1:
  case a2:
    break;
}
ready
switch numeric
switch ('asdf') {
  case b1:
  case b2:
    break;
}
ready

Revisions

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