33
33
/** Benchmark BLS12-381 G1 and G2 MSM */
34
34
public class BLS12Benchmark extends BenchmarkExecutor {
35
35
36
- /** Benchmark BLS12-381 G1 and G2 MSM with default warmup and iterations */
37
- public BLS12Benchmark () {
38
- super (MATH_WARMUP , MATH_ITERATIONS );
36
+ /**
37
+ * The constructor. Use default math based warmup and interations.
38
+ *
39
+ * @param output where to write the stats.
40
+ * @param benchmarkConfig benchmark configurations.
41
+ */
42
+ public BLS12Benchmark (final PrintStream output , final BenchmarkConfig benchmarkConfig ) {
43
+ super (MATH_WARMUP , MATH_ITERATIONS , output , benchmarkConfig );
39
44
}
40
45
41
46
static final String [] scalars = {
@@ -144,8 +149,7 @@ public BLS12Benchmark() {
144
149
};
145
150
146
151
@ Override
147
- public void runBenchmark (
148
- final PrintStream output , final Boolean attemptNative , final String fork ) {
152
+ public void runBenchmark (final Boolean attemptNative , final String fork ) {
149
153
150
154
EvmSpecVersion forkVersion = EvmSpecVersion .fromName (fork );
151
155
@@ -179,12 +183,12 @@ private void benchmarkG1Add(final PrintStream output) {
179
183
}
180
184
181
185
BLS12G1AddPrecompiledContract g1addContract = new BLS12G1AddPrecompiledContract ();
182
- warmup = MATH_WARMUP / testCases .size ();
183
- iterations = MATH_ITERATIONS / testCases .size ();
186
+ warmIterations = MATH_WARMUP / testCases .size ();
187
+ execIterations = MATH_ITERATIONS / testCases .size ();
184
188
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
185
189
long gasCost = 0 ;
186
190
for (final Map .Entry <String , Bytes > testCase : testCases .entrySet ()) {
187
- execTime += runPrecompileBenchmark (testCase .getValue (), g1addContract );
191
+ execTime += runPrecompileBenchmark (testCase .getKey (), testCase . getValue (), g1addContract );
188
192
gasCost += g1addContract .gasRequirement (testCase .getValue ());
189
193
}
190
194
execTime /= testCases .size ();
@@ -203,16 +207,16 @@ private void benchmarkG1MultiExp32Pairs(final PrintStream output) {
203
207
for (int j = 0 ; j < 1 << i ; j ++) {
204
208
g1msmPairs .append (g1PointPairs [j ]).append (scalars [j ]);
205
209
}
206
- testCases .put ("G1 MSM, " + (1 << i ) + " pairs" , Bytes .fromHexString (g1msmPairs .toString ()));
210
+ testCases .put ("G1 MSM " + (1 << i ) + " pairs" , Bytes .fromHexString (g1msmPairs .toString ()));
207
211
}
208
212
209
213
BLS12G1MultiExpPrecompiledContract g1msmContract = new BLS12G1MultiExpPrecompiledContract ();
210
- warmup = MATH_WARMUP / testCases .size ();
211
- iterations = MATH_ITERATIONS / testCases .size ();
214
+ warmIterations = MATH_WARMUP / testCases .size ();
215
+ execIterations = MATH_ITERATIONS / testCases .size ();
212
216
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
213
217
long gasCost = 0 ;
214
218
for (final Map .Entry <String , Bytes > testCase : testCases .entrySet ()) {
215
- execTime += runPrecompileBenchmark (testCase .getValue (), g1msmContract );
219
+ execTime += runPrecompileBenchmark (testCase .getKey (), testCase . getValue (), g1msmContract );
216
220
gasCost += g1msmContract .gasRequirement (testCase .getValue ());
217
221
}
218
222
output .printf (
@@ -227,12 +231,13 @@ private void benchmarkMapFpToG1(final PrintStream output) {
227
231
}
228
232
229
233
BLS12MapFpToG1PrecompiledContract g1MapFpToG1Contract = new BLS12MapFpToG1PrecompiledContract ();
230
- warmup = MATH_WARMUP / testCases .size ();
231
- iterations = MATH_ITERATIONS / testCases .size ();
234
+ warmIterations = MATH_WARMUP / testCases .size ();
235
+ execIterations = MATH_ITERATIONS / testCases .size ();
232
236
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
233
237
long gasCost = 0 ;
234
238
for (final Map .Entry <String , Bytes > testCase : testCases .entrySet ()) {
235
- execTime += runPrecompileBenchmark (testCase .getValue (), g1MapFpToG1Contract );
239
+ execTime +=
240
+ runPrecompileBenchmark (testCase .getKey (), testCase .getValue (), g1MapFpToG1Contract );
236
241
gasCost += g1MapFpToG1Contract .gasRequirement (testCase .getValue ());
237
242
}
238
243
execTime /= testCases .size ();
@@ -249,12 +254,12 @@ private void benchmarkG2Add(final PrintStream output) {
249
254
}
250
255
251
256
BLS12G2AddPrecompiledContract g1addContract = new BLS12G2AddPrecompiledContract ();
252
- warmup = MATH_WARMUP / testCases .size ();
253
- iterations = MATH_ITERATIONS / testCases .size ();
257
+ warmIterations = MATH_WARMUP / testCases .size ();
258
+ execIterations = MATH_ITERATIONS / testCases .size ();
254
259
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
255
260
long gasCost = 0 ;
256
261
for (final Map .Entry <String , Bytes > testCase : testCases .entrySet ()) {
257
- execTime += runPrecompileBenchmark (testCase .getValue (), g1addContract );
262
+ execTime += runPrecompileBenchmark (testCase .getKey (), testCase . getValue (), g1addContract );
258
263
gasCost += g1addContract .gasRequirement (testCase .getValue ());
259
264
}
260
265
execTime /= testCases .size ();
@@ -273,16 +278,16 @@ private void benchmarkG2MultiExp32Pairs(final PrintStream output) {
273
278
for (int j = 0 ; j < 1 << i ; j ++) {
274
279
g2msmPairs .append (g2PointPairs [j ]).append (scalars [j ]);
275
280
}
276
- testCases .put ("G2 MSM, " + (1 << i ) + " pairs" , Bytes .fromHexString (g2msmPairs .toString ()));
281
+ testCases .put ("G2 MSM " + (1 << i ) + " pairs" , Bytes .fromHexString (g2msmPairs .toString ()));
277
282
}
278
283
279
284
BLS12G2MultiExpPrecompiledContract g2msmContract = new BLS12G2MultiExpPrecompiledContract ();
280
- warmup = MATH_WARMUP / testCases .size ();
281
- iterations = MATH_ITERATIONS / testCases .size ();
285
+ warmIterations = MATH_WARMUP / testCases .size ();
286
+ execIterations = MATH_ITERATIONS / testCases .size ();
282
287
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
283
288
long gasCost = 0 ;
284
289
for (final Map .Entry <String , Bytes > testCase : testCases .entrySet ()) {
285
- execTime += runPrecompileBenchmark (testCase .getValue (), g2msmContract );
290
+ execTime += runPrecompileBenchmark (testCase .getKey (), testCase . getValue (), g2msmContract );
286
291
gasCost += g2msmContract .gasRequirement (testCase .getValue ());
287
292
}
288
293
output .printf (
@@ -298,12 +303,13 @@ private void benchmarkMapFp2ToG2(final PrintStream output) {
298
303
299
304
BLS12MapFp2ToG2PrecompiledContract g1MapFp2ToG2Contract =
300
305
new BLS12MapFp2ToG2PrecompiledContract ();
301
- warmup = MATH_WARMUP / testCases .size ();
302
- iterations = MATH_ITERATIONS / testCases .size ();
306
+ warmIterations = MATH_WARMUP / testCases .size ();
307
+ execIterations = MATH_ITERATIONS / testCases .size ();
303
308
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
304
309
long gasCost = 0 ;
305
310
for (final Map .Entry <String , Bytes > testCase : testCases .entrySet ()) {
306
- execTime += runPrecompileBenchmark (testCase .getValue (), g1MapFp2ToG2Contract );
311
+ execTime +=
312
+ runPrecompileBenchmark (testCase .getKey (), testCase .getValue (), g1MapFp2ToG2Contract );
307
313
gasCost += g1MapFp2ToG2Contract .gasRequirement (testCase .getValue ());
308
314
}
309
315
execTime /= testCases .size ();
@@ -322,16 +328,17 @@ private void benchmarkBlsPairing(final PrintStream output) {
322
328
for (int j = 0 ; j < 1 << i ; j ++) {
323
329
pairs .append (g1PointPairs [j ]).append (g2PointPairs [j ]);
324
330
}
325
- testCases .put ("BLS Pairing, " + (1 << i ) + " pairs" , Bytes .fromHexString (pairs .toString ()));
331
+ testCases .put ("BLS Pairing " + (1 << i ) + " pairs" , Bytes .fromHexString (pairs .toString ()));
326
332
}
327
333
328
334
BLS12PairingPrecompiledContract blsPairingContract = new BLS12PairingPrecompiledContract ();
329
- warmup = MATH_WARMUP / testCases .size ();
330
- iterations = MATH_ITERATIONS / testCases .size ();
335
+ warmIterations = MATH_WARMUP / testCases .size ();
336
+ execIterations = MATH_ITERATIONS / testCases .size ();
331
337
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
332
338
long gasCost = 0 ;
333
339
for (final Map .Entry <String , Bytes > testCase : testCases .entrySet ()) {
334
- execTime += runPrecompileBenchmark (testCase .getValue (), blsPairingContract );
340
+ execTime +=
341
+ runPrecompileBenchmark (testCase .getKey (), testCase .getValue (), blsPairingContract );
335
342
gasCost += blsPairingContract .gasRequirement (testCase .getValue ());
336
343
}
337
344
0 commit comments