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

Method runBenchmark

cli/command_benchmark_hashing.go:60–95  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

58}
59
60func (c *commandBenchmarkHashing) runBenchmark(ctx context.Context) []cryptoBenchResult {
61 var results []cryptoBenchResult
62
63 data := make([]byte, c.blockSize)
64
65 for _, ha := range hashing.SupportedAlgorithms() {
66 hf, err := hashing.CreateHashFunc(&format.ContentFormat{
67 Hash: ha,
68 HMACSecret: make([]byte, 32), //nolint:mnd
69 })
70 if err != nil {
71 continue
72 }
73
74 log(ctx).Infof("Benchmarking hash '%v' (%v x %v bytes, parallelism %v)", ha, c.repeat, len(data), c.parallel)
75
76 input := gather.FromSlice(data)
77 tt := timetrack.Start()
78
79 hashCount := c.repeat
80
81 runInParallelNoInputNoResult(c.parallel, func() {
82 var hashOutput [hashing.MaxHashSize]byte
83
84 for range hashCount {
85 hf(hashOutput[:0], input)
86 }
87 })
88
89 _, bytesPerSecond := tt.Completed(float64(c.parallel) * float64(len(data)) * float64(hashCount))
90
91 results = append(results, cryptoBenchResult{hash: ha, encryption: "-", throughput: bytesPerSecond})
92 }
93
94 return results
95}

Callers 1

runMethod · 0.95

Calls 6

SupportedAlgorithmsFunction · 0.92
CreateHashFuncFunction · 0.92
FromSliceFunction · 0.92
StartFunction · 0.92
CompletedMethod · 0.80

Tested by

no test coverage detected