-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigintinc_bench_test.go
80 lines (72 loc) · 3.52 KB
/
bigintinc_bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package biigist
import (
"math/big"
"testing"
"example.com/biigist/fp1280"
)
//go:generate go run fp1280_gen.go
func BenchmarkBigIntInc(b *testing.B) {
for _, v := range benchTableBigIntInc {
tBigInt, ok := big.NewInt(0).SetString(v.bignumstr, 10)
if !ok {
b.Fatalf("Failed to parse input as big int")
}
tBigIntCpy := big.NewInt(0).Set(tBigInt)
fpOne := fp1280.NewElement(1)
tfp := fp1280.NewElement(0)
tfp.SetString(v.bignumstr)
b.Run(v.name, func(b *testing.B) {
switch v.benchOp {
case BenchOpNewInt:
for i := 0; i < b.N; i++ {
big.NewInt(0).Set(tBigIntCpy)
}
case BenchOpNewIntAdd:
for i := 0; i < b.N; i++ {
bi := big.NewInt(0).Set(tBigIntCpy)
bi.Add(bi, one)
}
case BenchOpNewIntInc:
for i := 0; i < b.N; i++ {
bi := big.NewInt(0).Set(tBigIntCpy)
bigIntInc(bi)
}
case BenchOpAdd:
for i := 0; i < b.N; i++ {
tBigInt.Add(tBigInt, one)
}
case BenchOpInc:
for i := 0; i < b.N; i++ {
bigIntInc(tBigInt)
}
case BenchOpGnarkFAdd:
for i := 0; i < b.N; i++ {
tfp.Add(&tfp, &fpOne)
}
}
})
}
}
const (
BenchOpNewInt = uint8(iota) // reference values for add and inc
BenchOpNewIntAdd
BenchOpNewIntInc
BenchOpAdd
BenchOpInc
BenchOpGnarkFAdd
)
var benchTableBigIntInc = []struct {
name string
benchOp uint8
bignumstr string
}{
{"512bits_NewInt", BenchOpNewInt, "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095"},
{"512bits_NewInt_Add", BenchOpNewIntAdd, "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095"},
{"512bits_NewInt_Inc", BenchOpNewIntAdd, "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095"},
{"513bits_BIAdd", BenchOpAdd, "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096"},
{"513bits_GFAdd", BenchOpGnarkFAdd, "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096"},
{"513bits_Inc", BenchOpInc, "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096"},
{"1025bits_BIAdd", BenchOpAdd, "179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216"},
{"1025bits_GFAdd", BenchOpGnarkFAdd, "179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216"},
{"1025bits_Inc", BenchOpInc, "179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216"},
}