www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Benchmark games, Rust, big ints and Pi

reply "bearophile" <bearophileHUGS lycos.com> writes:
There is some discussion in the Rust Reddit, as Rust since some 
time has some benchmarks on the Computer Game site:
http://www.reddit.com/r/rust/comments/1xcq1q/c_gcc_vs_rust_wtf/

The source code of the Rust benchmarks is probably here:
https://github.com/mozilla/rust/tree/master/src/test/bench

They are mostly discussing about the very slow big int 
implementation.

A short D implementation of the the pidigits benchmark that uses 
Phobos BigInts (this is not meant to compete with the entries 
that use GMP. A D entry using GMP is possible), adapted from the 
C entry by the good Ledrug:

http://dpaste.dzfl.pl/821527e71343

I have not compared them, but I think it's 3-4 times slower than 
the best entry (that uses GMP).

I suspect that if Phobos BigInts gets mutable buffers 
(https://d.puremagic.com/issues/show_bug.cgi?id=7013 ), this code 
could be modified to be rather faster.

Bye,
bearophile
Feb 10 2014
parent reply "John Carter" <john.carter taitradio.com> writes:
On Monday, 10 February 2014 at 22:19:19 UTC, bearophile wrote:

 http://dpaste.dzfl.pl/821527e71343
Your paste has expired / no longer there.... but the subject has come up again... http://www.wilfred.me.uk/blog/2014/10/20/the-fastest-bigint-in-the-west/ https://lobste.rs/s/sfie8j/the_fastest_bigint_in_the_west I thought to take a poke at it from this point of view. Ruby "wins" the game for shortest code... I wondered whether D could score high both on the terse/readable and speed categories. Do you still have your implementation hanging around?
Oct 19 2014
parent "bearophile" <bearophileHUGS lycos.com> writes:
John Carter:

 Your paste has expired / no longer there.... but the subject 
 has come up again...
 ...
 Do you still have your implementation hanging around?
I think it was this. *Untested*: void main(string[] args) { import core.stdc.stdio, std.bigint, core.stdc.stdlib; immutable n = (args.length == 2) ? args[1].ptr.atoi : 100; BigInt acc, den = 1, num = 1; for (uint i, k; i < n; ) { immutable k2 = ++k * 2U + 1U; acc = (acc + num * 2U) * k2; den *= k2; num *= k; if (num > acc) continue; immutable d = ((num * 3 + acc) / den) % 10U; if (d != ((num * 4 + acc) / den) % 10U) continue; putchar('0' + d); if (++i % 10 == 0) printf("\t:%u\n", i); acc = (acc - den * d) * 10U; num *= 10U; } } Bye, bearophile
Oct 20 2014