digitalmars.D.learn - Benchmark games, Rust, big ints and Pi
- bearophile (19/19) Feb 10 2014 There is some discussion in the Rust Reddit, as Rust since some
- John Carter (9/10) Oct 19 2014 Your paste has expired / no longer there.... but the subject has
- bearophile (25/29) Oct 20 2014 I think it was this. *Untested*:
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
On Monday, 10 February 2014 at 22:19:19 UTC, bearophile wrote:http://dpaste.dzfl.pl/821527e71343Your 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
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