On Mon, Feb 11, 2013 at 1:05 PM, bearophile <bearophileh...@lycos.com>wrote:

>
>
> And isn't it better for the Rational constructor to simplify the arguments
> (calling an optimized GCD)? See this implementation (that doesn't use an
> optimized GCD):
>
> http://rosettacode.org/wiki/**Arithmetic/Rational#D<http://rosettacode.org/wiki/Arithmetic/Rational#D>
>
> Bye,
> bearophile
>

I ran some benchmarks, and I don't see how the rosetta version is more
optimized:  https://gist.github.com/Arlen/4947368

And the results on my 64-bit system, compiled with '-O -inline -release':

  Rosetta            rational + rational: 3333 ms
 Rosetta immutable  rational + rational: 3358 ms
 std                rational + rational: 2348 ms
 std immutable      rational + rational: 2197 ms

 Rosetta            rational - rational: 2822 ms
 Rosetta immutable  rational - rational: 2720 ms
 std                rational - rational: 1668 ms
 std immutable      rational - rational: 1583 ms

 Rosetta            rational * rational: 1628 ms
 Rosetta immutable  rational * rational: 1579 ms
 std                rational * rational: 1603 ms
 std immutable      rational * rational: 1500 ms

 Rosetta            rational / rational: 1636 ms
 Rosetta immutable  rational / rational: 1614 ms
 std                rational / rational: 1664 ms
 std immutable      rational / rational: 1534 ms

 Rosetta            rational == rational: 180 ms
 Rosetta immutable  rational == rational: 176 ms
 std                rational == rational: 90 ms
 std immutable      rational == rational: 80 ms

Arlen

Reply via email to