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