February 13, 2013
On Mon, Feb 11, 2013 at 1:05 PM, bearophile <bearophileHUGS@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


February 13, 2013
Arlen:

> I ran some benchmarks, and I don't see how the rosetta version is more optimized:

My message says "See this implementation (that doesn't use an optimized GCD):". I have never said that code is more optimized.

What I have said is that your version probably should simplify its arguments inside the constructor, possibly with an optimized GCD.

Bye,
bearophile
February 13, 2013
On Wed, Feb 13, 2013 at 3:48 PM, bearophile <bearophileHUGS@lycos.com>wrote:

> Arlen:
>
>
>  I ran some benchmarks, and I don't see how the rosetta version is more
>> optimized:
>>
>
> My message says "See this implementation (that doesn't use an optimized GCD):". I have never said that code is more optimized.
>
> What I have said is that your version probably should simplify its arguments inside the constructor, possibly with an optimized GCD.
>
> Bye,
> bearophile
>

Sorry, I misread what you said.

Maybe you mean something different by "simplify its arguments", but my version _does_ simplify its arguments inside the constructor.

As for "an optimized GCD", are you talking about binary GCD?

Arlen


February 13, 2013
Arlen:

> but my version _does_ simplify its arguments inside the constructor.

Right, sorry.


> As for "an optimized GCD", are you talking about binary GCD?

Right, but as we have seen a naive implementation of binary GCD gives no improvements:

http://d.puremagic.com/issues/show_bug.cgi?id=4125

Bye,
bearophile
1 2
Next ›   Last »