|
1 | 1 | import mir.bignum.integer: BigInt; |
2 | 2 | import mir.stdio; |
3 | 3 | import std.bigint: StdBigInt = BigInt; |
| 4 | +import gmp.z : GmpBigInt = MpZ, powmod; |
4 | 5 | import std.datetime.stopwatch; |
5 | 6 |
|
6 | 7 | immutable ps = "E5B5B1EDC8DF0F307C2220151CFCBE31F69B15659A5D6FBA1E50F55A08B341218312D707CFC16ED86A1765F5AEAFA7E6A11C4431038914C76F0F398FE6BE031E289B220D13D9E02226C691D15BC6E1186EA18222D93F52A393BE1DA1A42853512419B5E6E304FD02E962A4C2D0ECDDB8F44AC094FACA8333AE94110A5B10DA539C24A96F08530E7699E3F705165CF14B7F90A2F32ED28D21615F91D7C808AC566D6EEEF6773450AB53542CDAC337C3124530CB16319752267C3422149D41543D8742586BAB578F4E06360745AE0BD8F0E800D1920DC1F3661287367A78967458383A82465C5D966E7299EFCF58BD860185F96655E1F8D300F6B096DFE883CF15"; |
@@ -49,26 +50,53 @@ void testMir() |
49 | 50 | debug dout << b << endl; |
50 | 51 | } |
51 | 52 |
|
| 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 | + |
52 | 66 | void main() |
53 | 67 | { |
54 | 68 | version (assert) |
55 | 69 | { |
56 | | - testStd; |
57 | | - testMir; |
| 70 | + testStd(); |
| 71 | + testMir(); |
| 72 | + testGmp(); |
58 | 73 | dout << "please compile with --build=release" << endl; |
59 | 74 | } |
60 | 75 | else |
61 | 76 | { |
62 | 77 | 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 |
66 | 82 | << "--------------------------------------------" << 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 |
68 | 84 | << "std = " << res[0] << endl |
69 | 85 | << "mir = " << res[1] << endl |
70 | 86 | << " ............... " << size_t.sizeof * 8 << "bit " << os << " ............... " << endl |
71 | 87 | << "--------------------------------------------" |
72 | 88 | << 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 | + } |
73 | 101 | } |
74 | 102 | } |
0 commit comments