(ctx context.Context)
| 58 | } |
| 59 | |
| 60 | func (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 | } |
no test coverage detected