Files
kopia/cli/command_benchmark.go
Jarek Kowalski 0554e2f7ce refactor(general): introduced generics to reduce boilerplate code (#2527)
This removes tons of boilerplate code around:

- retry loop
- connection management
- storage registration

* used generics in runInParallel
* introduced generics in freepool
* introduced strong typing for workshare.Pool and workshare.AsyncGroup
* fixed linter error on openbsd
2022-10-29 01:56:51 +00:00

60 lines
1.1 KiB
Go

package cli
import (
"sync"
)
type commandBenchmark struct {
compression commandBenchmarkCompression
crypto commandBenchmarkCrypto
hashing commandBenchmarkHashing
encryption commandBenchmarkEncryption
splitters commandBenchmarkSplitters
ecc commandBenchmarkEcc
}
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)
c.ecc.setup(svc, cmd)
}
type cryptoBenchResult struct {
hash string
encryption string
throughput float64
}
func runInParallelNoResult(parallel int, run func()) {
runInParallel(parallel, func() any {
run()
return nil
})
}
func runInParallel[T any](parallel int, run func() T) T {
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
}