Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>equal? is reference equality == is value equality eql? is value and type equality </code></pre> <p>The third method, <code>eql?</code> is normally used to test if two objects have the same value as well as the same type. For example:</p> <pre><code>puts "integer == to float: #{25 == 25.0}" puts "integer eql? to float: #{25.eql? 25.0}" gives: Does integer == to float: true Does integer eql? to float: false </code></pre> <p>So I thought since <code>eql?</code> does more checking it would be slower, and for strings it is, at least on my Ruby 1.93. So I figured it must be type dependent and did some tests. When integer and floats are compared <code>eql?</code> is a bit faster. When integers are compared <code>==</code> is much faster, until x2. Wrong theory, back to start.</p> <p>The next theory: comparing two values of the same type will be faster with one of both proved to be true, in the case they are of the same type <code>==</code> is always faster, <code>eql?</code> is faster when types are different, again until x2.</p> <p>Don't have the time to compare all types but I'm sure you'll get varying results, although the same kind of comparison always gives similar results. Can somebody prove me wrong?</p> <p>Here are my results from the test of the OP:</p> <pre><code> 16.863000 0.000000 16.863000 ( 16.903000) 2 strings with eql? 14.212000 0.000000 14.212000 ( 14.334600) 2 strings with == 13.213000 0.000000 13.213000 ( 13.245600) integer and floating with eql? 14.103000 0.000000 14.103000 ( 14.200400) integer and floating with == 13.229000 0.000000 13.229000 ( 13.410800) 2 same integers with eql? 9.406000 0.000000 9.406000 ( 9.410000) 2 same integers with == 19.625000 0.000000 19.625000 ( 19.720800) 2 different integers with eql? 9.407000 0.000000 9.407000 ( 9.405800) 2 different integers with == 21.825000 0.000000 21.825000 ( 21.910200) integer with string with eql? 43.836000 0.031000 43.867000 ( 44.074200) integer with string with == </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload