Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bigint_benchmark/dub.sdl
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
name "bigint_benchmark"
dependency "mir-algorithm" path="../"
dependency "gmp-d" version="~master"
40 changes: 34 additions & 6 deletions bigint_benchmark/source/app.d
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}
}
}