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

Method runBenchmark

cli/command_benchmark_encryption.go:63–108  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

61}
62
63func (c *commandBenchmarkEncryption) runBenchmark(ctx context.Context) []cryptoBenchResult {
64 var results []cryptoBenchResult
65
66 data := make([]byte, c.blockSize)
67
68 for _, ea := range encryption.SupportedAlgorithms(c.deprecatedAlgorithms) {
69 enc, err := encryption.CreateEncryptor(&format.ContentFormat{
70 Encryption: ea,
71 Hash: hashing.DefaultAlgorithm,
72 MasterKey: make([]byte, 32), //nolint:mnd
73 HMACSecret: make([]byte, 32), //nolint:mnd
74 })
75 if err != nil {
76 continue
77 }
78
79 log(ctx).Infof("Benchmarking encryption '%v'... (%v x %v bytes, parallelism %v)", ea, c.repeat, len(data), c.parallel)
80
81 input := gather.FromSlice(data)
82 tt := timetrack.Start()
83
84 hashCount := c.repeat
85
86 runInParallelNoInputNoResult(c.parallel, func() {
87 var hashOutput [hashing.MaxHashSize]byte
88
89 var encryptOutput gather.WriteBuffer
90 defer encryptOutput.Close()
91
92 for range hashCount {
93 encryptOutput.Reset()
94
95 if encerr := enc.Encrypt(input, hashOutput[:32], &encryptOutput); encerr != nil {
96 log(ctx).Errorf("encryption failed: %v", encerr)
97 break
98 }
99 }
100 })
101
102 _, bytesPerSecond := tt.Completed(float64(c.parallel) * float64(len(data)) * float64(hashCount))
103
104 results = append(results, cryptoBenchResult{hash: "-", encryption: ea, throughput: bytesPerSecond})
105 }
106
107 return results
108}

Callers 1

runMethod · 0.95

Calls 10

CloseMethod · 0.95
ResetMethod · 0.95
SupportedAlgorithmsFunction · 0.92
CreateEncryptorFunction · 0.92
FromSliceFunction · 0.92
StartFunction · 0.92
ErrorfMethod · 0.80
CompletedMethod · 0.80
EncryptMethod · 0.65

Tested by

no test coverage detected