mirror of
https://github.com/kopia/kopia.git
synced 2026-05-16 10:44:40 -04:00
Option to print out the commands for benchmark (#779)
* Option to print out the commands for using crypto, splitter and compression Co-authored-by: Janne Johansson <janne.johansson@safespring.com> Co-authored-by: Jarek Kowalski <jaak@jkowalski.net>
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
"math/rand"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -13,13 +15,14 @@
|
||||
)
|
||||
|
||||
var (
|
||||
benchmarkSplitterCommand = benchmarkCommands.Command("splitter", "Run splitter benchmarks")
|
||||
benchmarkSplitterRandSeed = benchmarkSplitterCommand.Flag("rand-seed", "Random seed").Default("42").Int64()
|
||||
benchmarkSplitterBlockSize = benchmarkSplitterCommand.Flag("data-size", "Size of a data to split").Default("32MB").Bytes()
|
||||
benchmarkSplitterBlockCount = benchmarkSplitterCommand.Flag("block-count", "Number of data blocks to split").Default("16").Int()
|
||||
benchmarkSplitterCommand = benchmarkCommands.Command("splitter", "Run splitter benchmarks")
|
||||
benchmarkSplitterRandSeed = benchmarkSplitterCommand.Flag("rand-seed", "Random seed").Default("42").Int64()
|
||||
benchmarkSplitterBlockSize = benchmarkSplitterCommand.Flag("data-size", "Size of a data to split").Default("32MB").Bytes()
|
||||
benchmarkSplitterBlockCount = benchmarkSplitterCommand.Flag("block-count", "Number of data blocks to split").Default("16").Int()
|
||||
benchmarkSplitterPrintOption = benchmarkSplitterCommand.Flag("print-options", "Print out fastest dynamic splitter option").Bool()
|
||||
)
|
||||
|
||||
func runBenchmarkSplitterAction(ctx context.Context) error {
|
||||
func runBenchmarkSplitterAction(ctx context.Context) error { //nolint:funlen
|
||||
type benchResult struct {
|
||||
splitter string
|
||||
duration time.Duration
|
||||
@@ -35,6 +38,10 @@ type benchResult struct {
|
||||
|
||||
var results []benchResult
|
||||
|
||||
var best benchResult
|
||||
|
||||
best.duration = math.MaxInt64
|
||||
|
||||
// generate data blocks
|
||||
var dataBlocks [][]byte
|
||||
|
||||
@@ -112,6 +119,14 @@ type benchResult struct {
|
||||
r.duration.Nanoseconds()/1e6,
|
||||
r.segmentCount,
|
||||
r.min, r.p10, r.p25, r.p50, r.p75, r.p90, r.max)
|
||||
|
||||
if best.duration > r.duration && !strings.HasPrefix(r.splitter, "FIXED") {
|
||||
best = r
|
||||
}
|
||||
}
|
||||
|
||||
if *benchmarkSplitterPrintOption {
|
||||
printStdout("Fastest option for this machine is: --object-splitter=%s\n", best.splitter)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user