diff --git a/bigint_benchmark/dub.sdl b/bigint_benchmark/dub.sdl index 37e74f1e..5b57848a 100644 --- a/bigint_benchmark/dub.sdl +++ b/bigint_benchmark/dub.sdl @@ -1,2 +1,3 @@ name "bigint_benchmark" dependency "mir-algorithm" path="../" +dependency "gmp-d" version="~master" diff --git a/bigint_benchmark/source/app.d b/bigint_benchmark/source/app.d index e0b67237..ed60869b 100644 --- a/bigint_benchmark/source/app.d +++ b/bigint_benchmark/source/app.d @@ -1,6 +1,7 @@ import mir.bignum.integer: BigInt; import mir.stdio; import std.bigint: StdBigInt = BigInt; +import gmp.z : GmpBigInt = MpZ, powmod; import std.datetime.stopwatch; immutable ps = "E5B5B1EDC8DF0F307C2220151CFCBE31F69B15659A5D6FBA1E50F55A08B341218312D707CFC16ED86A1765F5AEAFA7E6A11C4431038914C76F0F398FE6BE031E289B220D13D9E02226C691D15BC6E1186EA18222D93F52A393BE1DA1A42853512419B5E6E304FD02E962A4C2D0ECDDB8F44AC094FACA8333AE94110A5B10DA539C24A96F08530E7699E3F705165CF14B7F90A2F32ED28D21615F91D7C808AC566D6EEEF6773450AB53542CDAC337C3124530CB16319752267C3422149D41543D8742586BAB578F4E06360745AE0BD8F0E800D1920DC1F3661287367A78967458383A82465C5D966E7299EFCF58BD860185F96655E1F8D300F6B096DFE883CF15"; @@ -49,26 +50,53 @@ void testMir() debug dout << b << endl; } +void testGmp() +{ + import std.algorithm.mutation : move; + auto p = GmpBigInt.fromHexString(ps); + auto q = GmpBigInt.fromHexString(qs); + GmpBigInt m = p.move(); + m *= q; + auto e = GmpBigInt.fromHexString(es); + GmpBigInt b = e.dup; + b.powmod(e, m); + debug dout << b << endl; +} + void main() { version (assert) { - testStd; - testMir; + testStd(); + testMir(); + testGmp(); dout << "please compile with --build=release" << endl; } else { import std.system: os; - auto res = 10.benchmark!(testStd, testMir); - auto ratio = double(res[0].total!"usecs") / res[1].total!"usecs"; - dout + const res = 10.benchmark!(testStd, testMir, testGmp); + { + const mirRatio = double(res[0].total!"usecs") / res[1].total!"usecs"; + dout << "--------------------------------------------" << endl - << "mir speedup = " << cast(int)((ratio - 1) * 100_0) / 10.0 << "%" << endl + << "mir speedup = " << cast(int)((mirRatio - 1) * 100_0) / 10.0 << "%" << endl << "std = " << res[0] << endl << "mir = " << res[1] << endl << " ............... " << size_t.sizeof * 8 << "bit " << os << " ............... " << endl << "--------------------------------------------" << endl; + } + { + const gmpRatio = double(res[0].total!"usecs") / res[2].total!"usecs"; + dout + << "--------------------------------------------" << endl + << "gmp speedup = " << cast(int)((gmpRatio - 1) * 100_0) / 10.0 << "%" << endl + << "std = " << res[0] << endl + << "gmp = " << res[2] << endl + << " ............... " << size_t.sizeof * 8 << "bit " << os << " ............... " << endl + << "--------------------------------------------" + << endl; + } } }