Loading ...
Sorry, an error occurred while loading the content.

Fwd: eqeq versus eqeqeq performance

Expand Messages
  • taffydb-owner@yahoogroups.com
    From Michael Mikowski: Hi everyone: We had been discussing retaining exact match the default for TaffyDB. So when in doubt, profile! My benchmarks show that
    Message 1 of 1 , Jun 20, 2012
    • 0 Attachment
      From Michael Mikowski:

      Hi everyone:

      We had been discussing retaining exact match the default for TaffyDB.
      So when in doubt, profile!

      My benchmarks show that '===' is 10 times faster than '==' when
      testing disparate data types, and 16 times faster when comparing
      strings and numbers only.  I am not surprised that '===' is faster,
      but the magnitude is surprising.

      In the attached benchmark, we test 1,000,000 pairs of data, e.g. [
      data_1, data_2 ], where data_1 and data_2 may be a random number, a
      stringified random number, a small array, or a small object.  Thus the
      data types only match 25% of the time.

      The benchmark isolates the equality tests in the timing loops, and
      removes and calculation or look-ups.

      Results on my Quad-core 64 bit Xeon (E31225 @ 3.10GH) with 8G ram
      system using node 0.6.19 (V8) with 1 million data pairs:

      node ./bench_comparitor.js
      Start of benchmark
      === time (ms):  34
      ==  time (ms):  342
      End of benchmark

      // code revised to check inequality
      //
      Start of benchmark
      !== time (ms):  35
      !=  time (ms):  345
      End of benchmark


      This is about a 10x performance improvement.  What is more remarkable,
      is that if we limit the data sets to only string and number types on
      line 48:
        idx_type = Math.floor( Math.random() * 2 + 0.99 )

      This results in the types matching 50% of the time.  And the advantage
      to === actually improves:

      # code revised to check only strings and numbers
      #
      node ./bench_comparitor.js
      Start of benchmark
      === time (ms):  31
      ==  time (ms):  498
      End of benchmark

      # code revised to check inequality
      #
      Start of benchmark
      !== time (ms):  31
      !=  time (ms):  466
      End of benchmark


      This is around a 16x performance advantage (e.g. 1,600% of  '=='
      speed).  If you play with the benchmark code, you can un-comment some
      lines to see the dataset that is being used.  It is recommended you
      reduce the count_loop config to a small number (e.g. 10) before doing
      so, or your terminal will be a mess.

      Anyway you slice it, '===' and '!==' look around an order of magnitude
      faster than '==' and '!='.  If we want TaffyDB to be the fastest out
      of the box, then it looks like exact-match-as-default is the right way
      to go.

      Sincerely, Mike
    Your message has been successfully submitted and would be delivered to recipients shortly.