MCPcopy
hub / github.com/kopia/kopia / runBenchmark

Method runBenchmark

cli/command_benchmark_ecc.go:69–151  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

67}
68
69func (c *commandBenchmarkEcc) runBenchmark(ctx context.Context) []eccBenchResult {
70 var results []eccBenchResult
71
72 data := make([]byte, c.blockSize)
73
74 //nolint:gosec
75 for i := range uint64(c.blockSize) {
76 data[i] = byte(i%255 + 1)
77 }
78
79 var encodedBuffer gather.WriteBuffer
80 defer encodedBuffer.Close()
81
82 for _, name := range ecc.SupportedAlgorithms() {
83 for _, spaceOverhead := range []int{1, 2, 5, 10, 20} {
84 impl, err := ecc.CreateAlgorithm(&ecc.Options{
85 Algorithm: ecc.AlgorithmReedSolomonWithCrc32,
86 OverheadPercent: spaceOverhead,
87 DeleteFirstShardForTests: true,
88 })
89 if err != nil {
90 continue
91 }
92
93 log(ctx).Infof("Benchmarking ECC encoding '%v' with %v space overhead... (%v x %v bytes, parallelism %v)", name, spaceOverhead, c.repeat, len(data), c.parallel)
94
95 input := gather.FromSlice(data)
96 tt := timetrack.Start()
97
98 repeat := c.repeat
99
100 runInParallelNoInputNoResult(c.parallel, func() {
101 var tmp gather.WriteBuffer
102 defer tmp.Close()
103
104 for range repeat {
105 if encerr := impl.Encrypt(input, nil, &tmp); encerr != nil {
106 log(ctx).Errorf("encoding failed: %v", encerr)
107 break
108 }
109 }
110 })
111
112 _, bytesPerSecondEncoding := tt.Completed(float64(c.parallel) * float64(len(data)) * float64(repeat))
113
114 log(ctx).Infof("Benchmarking ECC decoding '%v' with %v space overhead... (%v x %v bytes, parallelism %v)", name, spaceOverhead, c.repeat, len(data), c.parallel)
115
116 encodedBuffer.Reset()
117
118 if err := impl.Encrypt(gather.FromSlice(data), nil, &encodedBuffer); err != nil {
119 log(ctx).Errorf("encoding failed: %v", err)
120 break
121 }
122
123 input = encodedBuffer.Bytes()
124 tt = timetrack.Start()
125
126 runInParallelNoInputNoResult(c.parallel, func() {

Callers 1

runMethod · 0.95

Calls 13

CloseMethod · 0.95
ResetMethod · 0.95
BytesMethod · 0.95
SupportedAlgorithmsFunction · 0.92
CreateAlgorithmFunction · 0.92
FromSliceFunction · 0.92
StartFunction · 0.92
ErrorfMethod · 0.80
CompletedMethod · 0.80
EncryptMethod · 0.65
DecryptMethod · 0.65

Tested by

no test coverage detected