[Numpy-discussion] Speed of class derived from float64

Romain Brette romain.brette@ens...
Fri Sep 11 06:52:40 CDT 2009


Hi,

In our project we define a class derived from numpy.float64 (and we add units)
and I noticed that instance creation was very slow. I found out that creating a
float64 object is fast, but creating an object from the derived class is almost
10 times slower, even if that class doesn't do anything new. For example:

class C(float64):
    pass

x=float64(5.) takes 0.6 µs
x=float64() takes 0.5 µs
x=C(5.) takes 3.9 µs
x=C() takes 0.6 µs
Finally, if C derives from float instead of float64, x=C(5.) takes 0.3 µs.

What I find surprising is that the extra time is only when the object is
initialized with a value.
Does anybody have an idea about it? (and possibly a solution to make it faster?)

Romain





More information about the NumPy-Discussion mailing list