<br><br><div class="gmail_quote">On Mon, Feb 11, 2013 at 1:05 PM, bearophile <span dir="ltr"><<a href="mailto:bearophileHUGS@lycos.com" target="_blank">bearophileHUGS@lycos.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
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):<br>
<br>
<a href="http://rosettacode.org/wiki/Arithmetic/Rational#D" target="_blank">http://rosettacode.org/wiki/<u></u>Arithmetic/Rational#D</a><br>
<br>
Bye,<br>
bearophile<br>
</blockquote></div><br>I ran some benchmarks, and I don't see how the rosetta version is more optimized:  <a href="https://gist.github.com/Arlen/4947368">https://gist.github.com/Arlen/4947368</a><br><br>And the results on my 64-bit system, compiled with '-O -inline -release':<br>
<br>  <span style="font-family:courier new,monospace">Rosetta            rational + rational: 3333 ms<br> Rosetta immutable  rational + rational: 3358 ms<br> std                rational + rational: 2348 ms<br> std immutable      rational + rational: 2197 ms<br>
<br> Rosetta            rational - rational: 2822 ms<br> Rosetta immutable  rational - rational: 2720 ms<br> std                rational - rational: 1668 ms<br> std immutable      rational - rational: 1583 ms<br><br> Rosetta            rational * rational: 1628 ms<br>
 Rosetta immutable  rational * rational: 1579 ms<br> std                rational * rational: 1603 ms<br> std immutable      rational * rational: 1500 ms<br><br> Rosetta            rational / rational: 1636 ms<br> Rosetta immutable  rational / rational: 1614 ms<br>
 std                rational / rational: 1664 ms<br> std immutable      rational / rational: 1534 ms<br><br> Rosetta            rational == rational: 180 ms<br> Rosetta immutable  rational == rational: 176 ms<br> std                rational == rational: 90 ms<br>
 std immutable      rational == rational: 80 ms</span><br><br>Arlen<br>