Antoon Pardon <antoon.par...@rece.vub.ac.be> writes:

> You don't seem to understand. I only do two comparisons and no the
> equality is not necesarrily cheaper.
>
> I am talking about the difference between the following two:
>
>     if arg.key < node.key:   # possible expensive computation
>         go_left()
>     elif arg.key == node.key # possible expensive computation
>         found_node()
>     else:
>         go_right()
>
> and
>
>     delta = cmp(arg.key, node.key) # possible expensive computation
>     if delta < 0:                  # cheap computation
>         go_left()
>     elif delta == 0:               # cheap computation
>       found_node()
>     else:
>         go_right()

I find that a dubious claim.

The ‘cmp’ implementation must decide *at least* between three
conditions: less-than, equal-to, greater-than. That is *at least* two
inflection points.

The implementation of ‘__lt__’ and the implementation of ‘__eq__’ each
only need to decide two conditions (true, false). So that is *at most*
two inflection points.

If you're saying the latter implementation is somehow *more* expensive
than the former, I think the implementations are suspect and likely can
be improved: at least parity should be possible, to the point of
statistical insignificance.

-- 
 \        “Perchance you who pronounce my sentence are in greater fear |
  `\   than I who receive it.” —Giordano Bruno, burned at the stake by |
_o__)  the Catholic church for the heresy of heliocentrism, 1600-02-16 |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to