Skip to content

Commit 3024b5c

Browse files
authored
Also test using gmp-d in bigint_benchmark (#411)
1 parent efc54dc commit 3024b5c

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

bigint_benchmark/dub.sdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
name "bigint_benchmark"
22
dependency "mir-algorithm" path="../"
3+
dependency "gmp-d" version="~master"

bigint_benchmark/source/app.d

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import mir.bignum.integer: BigInt;
22
import mir.stdio;
33
import std.bigint: StdBigInt = BigInt;
4+
import gmp.z : GmpBigInt = MpZ, powmod;
45
import std.datetime.stopwatch;
56

67
immutable ps = "E5B5B1EDC8DF0F307C2220151CFCBE31F69B15659A5D6FBA1E50F55A08B341218312D707CFC16ED86A1765F5AEAFA7E6A11C4431038914C76F0F398FE6BE031E289B220D13D9E02226C691D15BC6E1186EA18222D93F52A393BE1DA1A42853512419B5E6E304FD02E962A4C2D0ECDDB8F44AC094FACA8333AE94110A5B10DA539C24A96F08530E7699E3F705165CF14B7F90A2F32ED28D21615F91D7C808AC566D6EEEF6773450AB53542CDAC337C3124530CB16319752267C3422149D41543D8742586BAB578F4E06360745AE0BD8F0E800D1920DC1F3661287367A78967458383A82465C5D966E7299EFCF58BD860185F96655E1F8D300F6B096DFE883CF15";
@@ -49,26 +50,53 @@ void testMir()
4950
debug dout << b << endl;
5051
}
5152

53+
void testGmp()
54+
{
55+
import std.algorithm.mutation : move;
56+
auto p = GmpBigInt.fromHexString(ps);
57+
auto q = GmpBigInt.fromHexString(qs);
58+
GmpBigInt m = p.move();
59+
m *= q;
60+
auto e = GmpBigInt.fromHexString(es);
61+
GmpBigInt b = e.dup;
62+
b.powmod(e, m);
63+
debug dout << b << endl;
64+
}
65+
5266
void main()
5367
{
5468
version (assert)
5569
{
56-
testStd;
57-
testMir;
70+
testStd();
71+
testMir();
72+
testGmp();
5873
dout << "please compile with --build=release" << endl;
5974
}
6075
else
6176
{
6277
import std.system: os;
63-
auto res = 10.benchmark!(testStd, testMir);
64-
auto ratio = double(res[0].total!"usecs") / res[1].total!"usecs";
65-
dout
78+
const res = 10.benchmark!(testStd, testMir, testGmp);
79+
{
80+
const mirRatio = double(res[0].total!"usecs") / res[1].total!"usecs";
81+
dout
6682
<< "--------------------------------------------" << endl
67-
<< "mir speedup = " << cast(int)((ratio - 1) * 100_0) / 10.0 << "%" << endl
83+
<< "mir speedup = " << cast(int)((mirRatio - 1) * 100_0) / 10.0 << "%" << endl
6884
<< "std = " << res[0] << endl
6985
<< "mir = " << res[1] << endl
7086
<< " ............... " << size_t.sizeof * 8 << "bit " << os << " ............... " << endl
7187
<< "--------------------------------------------"
7288
<< endl;
89+
}
90+
{
91+
const gmpRatio = double(res[0].total!"usecs") / res[2].total!"usecs";
92+
dout
93+
<< "--------------------------------------------" << endl
94+
<< "gmp speedup = " << cast(int)((gmpRatio - 1) * 100_0) / 10.0 << "%" << endl
95+
<< "std = " << res[0] << endl
96+
<< "gmp = " << res[2] << endl
97+
<< " ............... " << size_t.sizeof * 8 << "bit " << os << " ............... " << endl
98+
<< "--------------------------------------------"
99+
<< endl;
100+
}
73101
}
74102
}

0 commit comments

Comments
 (0)