forked from celestiaorg/rsmt2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extendeddatasquare_test.go
66 lines (60 loc) · 1.47 KB
/
extendeddatasquare_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
package rsmt2d
import (
"crypto/rand"
"fmt"
"reflect"
"testing"
)
func TestComputeExtendedDataSquare(t *testing.T) {
codec := NewRSGF8Codec()
result, err := ComputeExtendedDataSquare([][]byte{
{1}, {2},
{3}, {4},
}, codec, NewDefaultTree)
if err != nil {
panic(err)
}
if !reflect.DeepEqual(result.squareRow, [][][]byte{
{{1}, {2}, {7}, {13}},
{{3}, {4}, {13}, {31}},
{{5}, {14}, {19}, {41}},
{{9}, {26}, {47}, {69}},
}) {
t.Errorf("NewExtendedDataSquare failed for 2x2 square with chunk size 1")
}
}
// dump acts as a data dump for the benchmarks to stop the compiler from making
// unrealistic optimizations
var dump *ExtendedDataSquare
// BenchmarkExtension benchmarks extending datasquares sizes 4-128 using all supported codecs
func BenchmarkExtension(b *testing.B) {
for i := 4; i < 129; i *= 2 {
for codecName, codec := range codecs {
square := genRandDS(i)
b.Run(
fmt.Sprintf("%s size %d", codecName, i),
func(b *testing.B) {
for n := 0; n < b.N; n++ {
eds, err := ComputeExtendedDataSquare(square, codec, NewDefaultTree)
if err != nil {
b.Error(err)
}
dump = eds
}
},
)
}
}
}
// genRandDS make a datasquare of random data, with width describing the number
// of shares on a single side of the ds
func genRandDS(width int) [][]byte {
var ds [][]byte
count := width * width
for i := 0; i < count; i++ {
share := make([]byte, 256)
rand.Read(share)
ds = append(ds, share)
}
return ds
}