(ctx context.Context)
| 61 | } |
| 62 | |
| 63 | func (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 | } |
no test coverage detected