diff --git a/cli/command_benchmark_compression.go b/cli/command_benchmark_compression.go index a86b89abb..896404077 100644 --- a/cli/command_benchmark_compression.go +++ b/cli/command_benchmark_compression.go @@ -21,6 +21,7 @@ benchmarkCompressionDataFile = benchmarkCompressionCommand.Flag("data-file", "Use data from the given file instead of empty").ExistingFile() benchmarkCompressionBySize = benchmarkCompressionCommand.Flag("by-size", "Sort results by size").Bool() benchmarkCompressionVerifyStable = benchmarkCompressionCommand.Flag("verify-stable", "Verify that compression is stable").Bool() + benchmarkCompressionOptionPrint = benchmarkCompressionCommand.Flag("print-options", "Print out options usable for repository creation").Bool() ) func runBenchmarkCompressionAction(ctx context.Context) error { @@ -98,7 +99,13 @@ type benchResult struct { printStdout("-----------------------------------------------------------------\n") for ndx, r := range results { - printStdout("%3d. %-30v %-15v %v / second\n", ndx, r.compression, r.compressedSize, units.BytesStringBase2(int64(r.throughput))) + printStdout("%3d. %-30v %-15v %v / second", ndx, r.compression, r.compressedSize, units.BytesStringBase2(int64(r.throughput))) + + if *benchmarkCompressionOptionPrint { + printStdout(", --compression=%s", r.compression) + } + + printStdout("\n") } return nil diff --git a/cli/command_benchmark_crypto.go b/cli/command_benchmark_crypto.go index e66e95756..b0b66bbfe 100644 --- a/cli/command_benchmark_crypto.go +++ b/cli/command_benchmark_crypto.go @@ -16,6 +16,7 @@ benchmarkCryptoBlockSize = benchmarkCryptoCommand.Flag("block-size", "Size of a block to encrypt").Default("1MB").Bytes() benchmarkCryptoRepeat = benchmarkCryptoCommand.Flag("repeat", "Number of repetitions").Default("100").Int() benchmarkCryptoDeprecatedAlgorithms = benchmarkCryptoCommand.Flag("deprecated", "Include deprecated algorithms").Bool() + benchmarkCryptoOptionPrint = benchmarkCryptoCommand.Flag("print-options", "Print out options usable for repository creation").Bool() ) func runBenchmarkCryptoAction(ctx context.Context) error { @@ -78,9 +79,18 @@ type benchResult struct { printStdout("-----------------------------------------------------------------\n") for ndx, r := range results { - printStdout("%3d. %-20v %-20v %v / second\n", ndx, r.hash, r.encryption, units.BytesStringBase2(int64(r.throughput))) + printStdout("%3d. %-20v %-20v %v / second", ndx, r.hash, r.encryption, units.BytesStringBase2(int64(r.throughput))) + + if *benchmarkCryptoOptionPrint { + printStdout(", --block-hash=%s --encryption=%s", r.hash, r.encryption) + } + + printStdout("\n") } + printStdout("-----------------------------------------------------------------\n") + printStdout("Fastest option for this machine is: --block-hash==%s --encryption=%s\n", results[0].hash, results[0].encryption) + return nil } diff --git a/cli/command_benchmark_splitters.go b/cli/command_benchmark_splitters.go index 72963b91c..7fdbad65b 100644 --- a/cli/command_benchmark_splitters.go +++ b/cli/command_benchmark_splitters.go @@ -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