rails/rails — pull request #12200 by dchelimsky (2013-09-11 21:12:33+00:00)
Title: Reduce Duration#inspect to a single series of transformations

* eliminates need for temp local Hash

Also added a couple of examples to DurationTest to specify:

* duration can be defined with units out of order e.g. 1.month + 1.year + 1.second + 1.day
* equality with a Fixnum works regardless of which operand is on which side of the operator

This benchmarks faster than the current version under many circumstances. [I had previously stated that it was slower](https://github.com/rails/rails/pull/11856), but I had only benchmarked `1.year + 1.day + 1.month + 2.minutes + 1.day` with 10,000 repetitions. At 5k reps it roughly breaks even, and at 1k reps the new version is consistently faster. Also, with 3 parts e.g. `1.year + 1.day + 1.month` the new version is faster even at 10k reps.