MCPcopy
hub / github.com/kopia/kopia / run

Method run

cli/command_benchmark_compression.go:109–166  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

107}
108
109func (c *commandBenchmarkCompression) run(ctx context.Context) error {
110 var benchmarkCompression, benchmarkDecompression bool
111
112 data, err := c.readInputFile(ctx)
113 if err != nil {
114 return err
115 }
116
117 if len(data) == 0 {
118 return errors.New("empty data file")
119 }
120
121 repeatCount := c.repeat
122
123 if repeatCount == 0 {
124 repeatCount = defaultCompressedDataByMethod / len(data)
125
126 if repeatCount == 0 {
127 repeatCount = 1
128 }
129 }
130
131 algorithms := map[compression.Name]compression.Compressor{}
132
133 for name, comp := range compression.ByName {
134 if c.shouldIncludeAlgorithm(name) {
135 algorithms[name] = comp
136 }
137 }
138
139 log(ctx).Infof("Will repeat each benchmark %v times per compression method (total %v). Override with --repeat=N.", repeatCount, units.BytesString(repeatCount*len(data)))
140
141 switch c.operations {
142 case "compress":
143 benchmarkCompression = true
144 benchmarkDecompression = false
145 case "decompress":
146 benchmarkCompression = false
147 benchmarkDecompression = true
148 default:
149 benchmarkCompression = true
150 benchmarkDecompression = true
151 }
152
153 if benchmarkCompression {
154 if err := c.runCompression(ctx, data, repeatCount, algorithms); err != nil {
155 return err
156 }
157 }
158
159 if benchmarkDecompression {
160 if err := c.runDecompression(ctx, data, repeatCount, algorithms); err != nil {
161 return err
162 }
163 }
164
165 return nil
166}

Callers

nothing calls this directly

Calls 5

readInputFileMethod · 0.95
runCompressionMethod · 0.95
runDecompressionMethod · 0.95
BytesStringFunction · 0.92

Tested by

no test coverage detected