Files
kopia/cli/command_benchmark.go
Jarek Kowalski d7e10dba59 feat(cli): improved kopia benchmark commands (#1849)
* added --parallel flag
* added `kopia benchmark encryption`
* added `kopia benchmark hashing`
2022-03-26 14:28:08 +00:00

51 lines
945 B
Go

package cli
import (
"sync"
)
type commandBenchmark struct {
compression commandBenchmarkCompression
crypto commandBenchmarkCrypto
hashing commandBenchmarkHashing
encryption commandBenchmarkEncryption
splitters commandBenchmarkSplitters
}
func (c *commandBenchmark) setup(svc appServices, parent commandParent) {
cmd := parent.Command("benchmark", "Commands to test performance of algorithms.")
c.compression.setup(svc, cmd)
c.crypto.setup(svc, cmd)
c.splitters.setup(svc, cmd)
c.hashing.setup(svc, cmd)
c.encryption.setup(svc, cmd)
}
type cryptoBenchResult struct {
hash string
encryption string
throughput float64
}
func runInParallel(parallel int, run func() interface{}) interface{} {
var wg sync.WaitGroup
for i := 0; i < parallel-1; i++ {
wg.Add(1)
go func() {
defer wg.Done()
run()
}()
}
// run one on the main goroutine and N-1 in parallel.
v := run()
wg.Wait()
return v
}