diamondman / bitarray

efficient arrays of booleans for Python
Other
5 stars 2 forks source link

Expose number methods via PyNumberMethods. #10

Closed eltoder closed 8 years ago

eltoder commented 8 years ago

Same as with the sequence methods, this is more efficient:

Without my changes

Method Time Time / Int Time
~n 0.15731502 6.60738819571
not n 0.09582591 4.24574024191
n & n 0.25910902 8.98530809997
n n 0.24405813 8.56255959849
n ^ n 0.26799893 10.3437807695
n &= n 0.15009093 4.7497132941
n = n 0.15412307 5.11443490644
n ^= n 0.15293598 5.40846352959

With my changes

Method Time Time / Int Time
~n 0.09859705 4.17870964482
not n 0.02347922 1.06352257633
n & n 0.15802598 5.56467970783
n n 0.15931797 5.64720398212
n ^ n 0.17296290 6.74212135575
n &= n 0.06629801 2.15462695356
n = n 0.06553197 2.21512040231
n ^= n 0.06492305 2.32224970152

The last column is time relative to int.

This gives an average speed up of 2x on this benchmark. Of course, longer arrays will see smaller improvements.