Run executes the benchmark runs.
()
| 166 | |
| 167 | // Run executes the benchmark runs. |
| 168 | func (r *Runner) Run() error { |
| 169 | if err := validateConfig(r.config); err != nil { |
| 170 | return err |
| 171 | } |
| 172 | |
| 173 | var errs []error |
| 174 | |
| 175 | r.stats = r.stats[:] |
| 176 | |
| 177 | if r.config.SetupFunc != nil { |
| 178 | if _, err := r.config.SetupFunc(0, r.config); err != nil { |
| 179 | return err |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | for n := 1; n <= r.config.NumWarmups; n++ { |
| 184 | if _, err := r.config.RunnerFunc(n, r.config); err != nil { |
| 185 | errs = append(errs, err) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | for n := 1; n <= r.config.NumRepetitions; n++ { |
| 190 | stat := Stats{Start: time.Now().UTC()} |
| 191 | res, err := r.config.RunnerFunc(n, r.config) |
| 192 | if err != nil { |
| 193 | errs = append(errs, err) |
| 194 | stat.Outcome = "failure" |
| 195 | } else { |
| 196 | stat.Duration = time.Since(stat.Start) |
| 197 | stat.ResponseStatusCode = res.StatusCode |
| 198 | if res.IsError() { |
| 199 | errs = append(errs, fmt.Errorf("HTTP error: %s", res.String())) |
| 200 | stat.Outcome = "failure" |
| 201 | } else { |
| 202 | stat.Outcome = "success" |
| 203 | } |
| 204 | r.stats = append(r.stats, stat) |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | if err := r.SaveStats(); err != nil { |
| 209 | return err |
| 210 | } |
| 211 | |
| 212 | if len(errs) > 0 { |
| 213 | return &Error{err: fmt.Sprintf("encountered %d errors during the run", len(errs)), errs: errs} |
| 214 | } |
| 215 | return nil |
| 216 | } |
| 217 | |
| 218 | // Stats returns statistics about the run. |
| 219 | func (r *Runner) Stats() []Stats { |