2017-08-11 19:25:51 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/montanaflynn/stats"
|
|
|
|
)
|
|
|
|
|
|
|
|
var benchmark = app.Command("benchmark", "Repeat build for ten seconds. Implies --profile.")
|
|
|
|
|
|
|
|
// benchmarkCommand builds the site repeatedly until at least 10 seconds has elapsed,
|
|
|
|
// and reports the trial times. Empirically, it the same mean but low variance as using
|
|
|
|
// a separate benchmark runner that invokes a new gojekyll process each time.
|
|
|
|
func benchmarkCommand() (err error) {
|
|
|
|
startTime := time.Now()
|
2017-09-02 20:09:04 +02:00
|
|
|
var samples []float64
|
2017-08-11 19:25:51 +02:00
|
|
|
for i := 0; time.Since(startTime) < 10*time.Second; i++ {
|
|
|
|
sampleStart := time.Now()
|
|
|
|
site, err := loadSite(*source, options)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-08-16 21:50:31 +02:00
|
|
|
_, err = site.Write()
|
2017-08-11 19:25:51 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
dur := time.Since(sampleStart).Seconds()
|
|
|
|
samples = append(samples, dur)
|
|
|
|
quiet = true
|
|
|
|
fmt.Printf("Run #%d; %.1fs elapsed\n", i+1, time.Since(commandStartTime).Seconds())
|
|
|
|
}
|
|
|
|
median, _ := stats.Median(samples)
|
|
|
|
stddev, _ := stats.StandardDeviationSample(samples)
|
|
|
|
fmt.Printf("%d samples @ %.2fs ± %.2fs\n", len(samples), median, stddev)
|
|
|
|
return nil
|
|
|
|
}
|