@@ -90,7 +90,7 @@ func pokPedersenCommittmentInitKilic(b *testing.B) (io.Reader, *kilic.PointG1, *
9090 return rng , g , h , x
9191}
9292
93- func Benchmark_PedersenCommitmentPoKKilic (b * testing.B ) {
93+ func Benchmark_Sequential_PedersenCommitmentPoKKilic (b * testing.B ) {
9494 rng , g , h , x := pokPedersenCommittmentInitKilic (b )
9595 _g := kilic .NewG1 ()
9696 tmp := _g .New ()
@@ -135,7 +135,7 @@ func Benchmark_PedersenCommitmentPoKKilic(b *testing.B) {
135135 })
136136}
137137
138- func Benchmark_PedersenCommitmentPoKGurvy (b * testing.B ) {
138+ func Benchmark_Sequential_PedersenCommitmentPoKGurvy (b * testing.B ) {
139139 rng , g , h , x := pokPedersenCommittmentInitGurvy (b )
140140
141141 b .ResetTimer ()
@@ -171,7 +171,7 @@ func Benchmark_PedersenCommitmentPoKGurvy(b *testing.B) {
171171 })
172172}
173173
174- func Benchmark_PedersenCommitmentPoK (b * testing.B ) {
174+ func Benchmark_Sequential_PedersenCommitmentPoK (b * testing.B ) {
175175
176176 for _ , curve := range Curves {
177177 rng , g , h , x , err := pokPedersenCommittmentInit (b , curve )
@@ -212,110 +212,134 @@ func Benchmark_PedersenCommitmentPoK(b *testing.B) {
212212 }
213213}
214214
215- func Benchmark_BLSGurvy (b * testing.B ) {
215+ func Benchmark_Sequential_BLS (b * testing.B ) {
216+
217+ for _ , curve := range Curves {
218+ g , x , err := blsInit (b , curve )
219+ if err != nil {
220+ panic (err )
221+ }
222+
223+ pk := g .Mul (x )
224+
225+ b .ResetTimer ()
226+
227+ var sig * G1
228+
229+ b .Run (fmt .Sprintf ("sign curve %s" , CurveIDToString (curve .curveID )), func (b * testing.B ) {
230+ for i := 0 ; i < b .N ; i ++ {
231+ h := curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
232+ sig = h .Mul (x )
233+ }
234+ })
235+
236+ sig .Neg ()
237+
238+ b .Run (fmt .Sprintf ("verify curve %s" , CurveIDToString (curve .curveID )), func (b * testing.B ) {
239+ for i := 0 ; i < b .N ; i ++ {
240+ h := curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
241+
242+ p := curve .Pairing2 (g , sig , pk , h )
243+
244+ p = curve .FExp (p )
245+ if ! p .IsUnity () {
246+ panic ("invalid signature" )
247+ }
248+ }
249+ })
250+ }
251+ }
252+
253+ func Benchmark_Parallel_BLSGurvy (b * testing.B ) {
216254 g , x := blsInitGurvy (b )
217255 pk := new (bls12381.G2Affine ).ScalarMultiplication (g , x )
218256
219257 b .ResetTimer ()
220258
221259 var sig * bls12381.G1Affine
222260
223- for _ , parallelism := range []int {1 , 2 , 4 , 8 , 16 , 32 , 96 } {
224- b .Run (fmt .Sprintf ("sign curve BLS12_381_GURVY (direct)-p%d" , parallelism ), func (b * testing.B ) {
225- b .RunParallel (func (pb * testing.PB ) {
226- for pb .Next () {
227- h , err := bls12381 .HashToG1 ([]byte ("msg" ), []byte ("context" ))
228- if err != nil {
229- panic (err )
230- }
231- sig = new (bls12381.G1Affine ).ScalarMultiplication (& h , x )
261+ b .Run ("sign curve BLS12_381_GURVY (direct)" , func (b * testing.B ) {
262+ b .RunParallel (func (pb * testing.PB ) {
263+ for pb .Next () {
264+ h , err := bls12381 .HashToG1 ([]byte ("msg" ), []byte ("context" ))
265+ if err != nil {
266+ panic (err )
232267 }
233- })
268+ sig = new (bls12381.G1Affine ).ScalarMultiplication (& h , x )
269+ }
234270 })
235- }
271+ })
236272
237273 sig .Neg (sig )
238274
239275 b .ResetTimer ()
240276
241- for _ , parallelism := range []int {1 , 2 , 4 , 8 , 16 , 32 , 96 } {
242- b .Run (fmt .Sprintf ("verify curve BLS12_381_GURVY (direct)-p%d" , parallelism ), func (b * testing.B ) {
243- b .RunParallel (func (pb * testing.PB ) {
244- for pb .Next () {
245- h , err := bls12381 .HashToG1 ([]byte ("msg" ), []byte ("context" ))
246- if err != nil {
247- panic (err )
248- }
249-
250- t , err := bls12381 .MillerLoop ([]bls12381.G1Affine {* sig , h }, []bls12381.G2Affine {* g , * pk })
251- if err != nil {
252- panic (err )
253- }
254-
255- t1 := bls12381 .FinalExponentiation (& t )
256-
257- unity := & bls12381.GT {}
258- unity .SetOne ()
259- if ! unity .Equal (& t1 ) {
260- panic ("invalid signature" )
261- }
277+ b .Run ("verify curve BLS12_381_GURVY (direct)" , func (b * testing.B ) {
278+ b .RunParallel (func (pb * testing.PB ) {
279+ for pb .Next () {
280+ h , err := bls12381 .HashToG1 ([]byte ("msg" ), []byte ("context" ))
281+ if err != nil {
282+ panic (err )
283+ }
284+
285+ t , err := bls12381 .MillerLoop ([]bls12381.G1Affine {* sig , h }, []bls12381.G2Affine {* g , * pk })
286+ if err != nil {
287+ panic (err )
288+ }
289+
290+ t1 := bls12381 .FinalExponentiation (& t )
291+
292+ unity := & bls12381.GT {}
293+ unity .SetOne ()
294+ if ! unity .Equal (& t1 ) {
295+ panic ("invalid signature" )
262296 }
263- })
297+ }
264298 })
265- }
299+ })
266300}
267301
268- func Benchmark_BLS (b * testing.B ) {
302+ func Benchmark_Parallel_BLS (b * testing.B ) {
303+ curve := Curves [BLS12_381_GURVY ]
304+ g , x , err := blsInit (b , curve )
305+ if err != nil {
306+ panic (err )
307+ }
269308
270- for _ , curve := range Curves {
271- g , x , err := blsInit (b , curve )
272- if err != nil {
273- panic (err )
274- }
309+ pk := g .Mul (x )
275310
276- pk := g . Mul ( x )
311+ b . ResetTimer ( )
277312
278- b . ResetTimer ()
313+ var sig * G1
279314
280- var sig * G1
315+ b .Run (fmt .Sprintf ("sign curve %s" , CurveIDToString (curve .curveID )), func (b * testing.B ) {
316+ b .RunParallel (func (pb * testing.PB ) {
317+ for pb .Next () {
318+ h := curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
319+ sig = h .Mul (x )
320+ }
321+ })
322+ })
281323
282- for _ , parallelism := range []int {1 , 2 , 4 , 8 , 16 , 32 , 96 } {
283- b .Run (fmt .Sprintf ("sign curve %s-p%d" , CurveIDToString (curve .curveID ), parallelism ), func (b * testing.B ) {
284- b .RunParallel (func (pb * testing.PB ) {
285- for pb .Next () {
286- for i := 0 ; i < b .N ; i ++ {
287- h := curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
288- sig = h .Mul (x )
289- }
290- }
291- })
292- })
293- }
324+ sig .Neg ()
294325
295- sig .Neg ()
326+ b .Run (fmt .Sprintf ("verify curve %s" , CurveIDToString (curve .curveID )), func (b * testing.B ) {
327+ b .RunParallel (func (pb * testing.PB ) {
328+ for pb .Next () {
329+ h := curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
296330
297- for _ , parallelism := range []int {1 , 2 , 4 , 8 , 16 , 32 , 96 } {
298- b .Run (fmt .Sprintf ("verify curve %s-p%d" , CurveIDToString (curve .curveID ), parallelism ), func (b * testing.B ) {
299- b .RunParallel (func (pb * testing.PB ) {
300- for pb .Next () {
301- for i := 0 ; i < b .N ; i ++ {
302- h := curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
303-
304- p := curve .Pairing2 (g , sig , pk , h )
305-
306- p = curve .FExp (p )
307- if ! p .IsUnity () {
308- panic ("invalid signature" )
309- }
310- }
311- }
312- })
313- })
314- }
315- }
331+ p := curve .Pairing2 (g , sig , pk , h )
332+
333+ p = curve .FExp (p )
334+ if ! p .IsUnity () {
335+ panic ("invalid signature" )
336+ }
337+ }
338+ })
339+ })
316340}
317341
318- func Benchmark_IndividualOps (b * testing.B ) {
342+ func Benchmark_Parallel_IndividualOps (b * testing.B ) {
319343 curve := Curves [BLS12_381_GURVY ]
320344 g_gurv , x_gurv := blsInitGurvy (b )
321345 g_math , x_math , err := blsInit (b , curve )
@@ -335,71 +359,59 @@ func Benchmark_IndividualOps(b *testing.B) {
335359 var t_gurv bls12381.GT
336360 var t_math * Gt
337361
338- for _ , parallelism := range []int {1 , 2 , 4 , 8 , 16 , 32 , 96 } {
339- b .Run (fmt .Sprintf ("hash/gurvy-p%d" , parallelism ), func (b * testing.B ) {
340- b .RunParallel (func (pb * testing.PB ) {
341- for pb .Next () {
342- h_gurv , _ = bls12381 .HashToG1 ([]byte ("msg" ), []byte ("context" ))
343- }
344- })
362+ b .Run ("hash/gurvy" , func (b * testing.B ) {
363+ b .RunParallel (func (pb * testing.PB ) {
364+ for pb .Next () {
365+ h_gurv , _ = bls12381 .HashToG1 ([]byte ("msg" ), []byte ("context" ))
366+ }
345367 })
346- }
368+ })
347369
348- for _ , parallelism := range []int {1 , 2 , 4 , 8 , 16 , 32 , 96 } {
349- b .Run (fmt .Sprintf ("hash/mathlib-p%d" , parallelism ), func (b * testing.B ) {
350- b .RunParallel (func (pb * testing.PB ) {
351- for pb .Next () {
352- h_math = curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
353- }
354- })
370+ b .Run ("hash/mathlib" , func (b * testing.B ) {
371+ b .RunParallel (func (pb * testing.PB ) {
372+ for pb .Next () {
373+ h_math = curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
374+ }
355375 })
356- }
376+ })
357377
358- for _ , parallelism := range []int {1 , 2 , 4 , 8 , 16 , 32 , 96 } {
359- b .Run (fmt .Sprintf ("sign/gurvy-p%d" , parallelism ), func (b * testing.B ) {
360- b .RunParallel (func (pb * testing.PB ) {
361- for pb .Next () {
362- sig_gurv = new (bls12381.G1Affine ).ScalarMultiplication (& h_gurv , x_gurv )
363- }
364- })
378+ b .Run ("sign/gurvy" , func (b * testing.B ) {
379+ b .RunParallel (func (pb * testing.PB ) {
380+ for pb .Next () {
381+ sig_gurv = new (bls12381.G1Affine ).ScalarMultiplication (& h_gurv , x_gurv )
382+ }
365383 })
366- }
384+ })
367385
368- for _ , parallelism := range []int {1 , 2 , 4 , 8 , 16 , 32 , 96 } {
369- b .Run (fmt .Sprintf ("sign/mathlib-p%d" , parallelism ), func (b * testing.B ) {
370- b .RunParallel (func (pb * testing.PB ) {
371- for pb .Next () {
372- sig_math = h_math .Mul (x_math )
373- }
374- })
386+ b .Run ("sign/mathlib" , func (b * testing.B ) {
387+ b .RunParallel (func (pb * testing.PB ) {
388+ for pb .Next () {
389+ sig_math = h_math .Mul (x_math )
390+ }
375391 })
376- }
377-
378- for _ , parallelism := range []int {1 , 2 , 4 , 8 , 16 , 32 , 96 } {
379- b .Run (fmt .Sprintf ("pairing2/gurvy-p%d" , parallelism ), func (b * testing.B ) {
380- b .RunParallel (func (pb * testing.PB ) {
381- for pb .Next () {
392+ })
382393
383- t_gurv , err = bls12381 .MillerLoop ([]bls12381.G1Affine {* sig_gurv , h_gurv }, []bls12381.G2Affine {* g_gurv , * pk_gurv })
384- if err != nil {
385- panic (err )
386- }
394+ b .Run ("pairing2/gurvy" , func (b * testing.B ) {
395+ b .RunParallel (func (pb * testing.PB ) {
396+ for pb .Next () {
387397
388- t_gurv = bls12381 .FinalExponentiation (& t_gurv )
398+ t_gurv , err = bls12381 .MillerLoop ([]bls12381.G1Affine {* sig_gurv , h_gurv }, []bls12381.G2Affine {* g_gurv , * pk_gurv })
399+ if err != nil {
400+ panic (err )
389401 }
390- })
402+
403+ t_gurv = bls12381 .FinalExponentiation (& t_gurv )
404+ }
391405 })
392- }
406+ })
393407
394- for _ , parallelism := range []int {1 , 2 , 4 , 8 , 16 , 32 , 96 } {
395- b .Run (fmt .Sprintf ("pairing2/mathlib-p%d" , parallelism ), func (b * testing.B ) {
396- b .RunParallel (func (pb * testing.PB ) {
397- for pb .Next () {
398- t_math = curve .Pairing2 (g_math , sig_math , pk_math , h_math )
408+ b .Run ("pairing2/mathlib" , func (b * testing.B ) {
409+ b .RunParallel (func (pb * testing.PB ) {
410+ for pb .Next () {
411+ t_math = curve .Pairing2 (g_math , sig_math , pk_math , h_math )
399412
400- t_math = curve .FExp (t_math )
401- }
402- })
413+ t_math = curve .FExp (t_math )
414+ }
403415 })
404- }
416+ })
405417}
0 commit comments