astropy/astropy — pull request #1289 by mdboom (2013-07-26 19:47:27+00:00)
Title: Improves the speed of units

- Reduces unnecessary calls to sort that were used to create unique ids. It's faster to keep the powers and bases sorted in a canonical way all the time and then not have to re-sort on a regular basis.

- Memoize the `_compose` method by the unit -- this results in about 50% cache hits.

- Reduce the use of `fractions.Fraction` in calculations by converting Fractions with a power of 2 denominator. `Fraction` instances are still used for other rationals that cannot be represented exactly by a floating point number, and those will still be slow-but-accurate.

I got about 2x speed up on the following:

```
const.sigma_sb.cgs
```

(this was dominating import time of astropy.coordinates).

I also get about 1.1x speedup on the unit test suite as a whole. (Not that the unit tests are benchmarks :wink:)