(ctx context.Context)
| 41 | } |
| 42 | |
| 43 | func (c *commandBenchmarkSplitters) run(ctx context.Context) error { //nolint:funlen |
| 44 | type benchResult struct { |
| 45 | splitter string |
| 46 | duration time.Duration |
| 47 | segmentCount int |
| 48 | min int |
| 49 | p10 int |
| 50 | p25 int |
| 51 | p50 int |
| 52 | p75 int |
| 53 | p90 int |
| 54 | max int |
| 55 | bytesPerSecond int64 |
| 56 | } |
| 57 | |
| 58 | var results []benchResult |
| 59 | |
| 60 | var best benchResult |
| 61 | |
| 62 | best.duration = math.MaxInt64 |
| 63 | |
| 64 | // generate data blocks |
| 65 | var dataBlocks [][]byte |
| 66 | |
| 67 | rnd := rand.New(rand.NewSource(c.randSeed)) //nolint:gosec |
| 68 | |
| 69 | for range c.blockCount { |
| 70 | b := make([]byte, c.blockSize) |
| 71 | if _, err := rnd.Read(b); err != nil { |
| 72 | return errors.Wrap(err, "error generating random data") |
| 73 | } |
| 74 | |
| 75 | dataBlocks = append(dataBlocks, b) |
| 76 | } |
| 77 | |
| 78 | log(ctx).Infof("splitting %v blocks of %v each, parallelism %v", c.blockCount, c.blockSize, c.parallel) |
| 79 | |
| 80 | for _, sp := range splitter.SupportedAlgorithms() { |
| 81 | tt := timetrack.Start() |
| 82 | |
| 83 | segmentLengths := runInParallelNoInput(c.parallel, func() []int { |
| 84 | fact := splitter.GetFactory(sp) |
| 85 | |
| 86 | var segmentLengths []int |
| 87 | |
| 88 | for _, d := range dataBlocks { |
| 89 | s := fact() |
| 90 | |
| 91 | for len(d) > 0 { |
| 92 | n := s.NextSplitPoint(d) |
| 93 | if n < 0 { |
| 94 | segmentLengths = append(segmentLengths, len(d)) |
| 95 | break |
| 96 | } |
| 97 | |
| 98 | segmentLengths = append(segmentLengths, n) |
| 99 | d = d[n:] |
| 100 | } |
nothing calls this directly
no test coverage detected