[Python-Dev] performance (original) (raw)

Steven D'Aprano steve at pearwood.info
Mon Aug 25 01:54:48 CEST 2008


On Mon, 25 Aug 2008 05:04:16 am Antoine Pitrou wrote:

> >         CompareFloatsIntegers:    274ms    274ms    0.30us > >  0.630ms > > Much slower, but probably due to switch from int -> long.  There > could be potential for optimizing this case.

Well honestly you don't often compare different types. I think the most common exception to this rule would be None vs. non-None.

Surely the most common None vs non-None comparison would be the "is" operator, which I hope remains fast.

I don't know about other people, but I often compare floats with ints. Here's a contrived example:

x = some_float() if x == -1: return -2 else: return (x**2-1)/(x+1)

I suppose it's no hardship to start writing float literals instead of int literals, if needed.

-- Steven



More information about the Python-Dev mailing list