func RepetitionDurationStats(reps int, setup, f, teardown func() error) (time.Duration, time.Duration, error) {
	if reps < 1 {
		return time.Duration(0), 0, fmt.Errorf("repetions need to be %d >= 1", reps)
	}
	if setup == nil {
		return time.Duration(0), 0, errors.New("setup function is required")
	}
	if f == nil {
		return time.Duration(0), 0, errors.New("benchmark function is required")
	}
	if teardown == nil {
		return time.Duration(0), 0, errors.New("teardown function is required")
	}
	var durations []time.Duration
	for i := 0; i < reps; i++ {
		if err := setup(); err != nil {
			return time.Duration(0), 0, err
		}
		d, err := TrackDuration(f)
		if err != nil {
			return 0, 0, err
		}
		durations = append(durations, d)
		if err := teardown(); err != nil {
			return time.Duration(0), 0, err
		}
	}
	mean := int64(0)
	for _, d := range durations {
		mean += int64(d)
	}
	mean /= int64(len(durations))
	dev, expSquare := int64(0), mean*mean
	for _, d := range durations {
		dev = int64(d)*int64(d) - expSquare
	}
	dev = int64(math.Sqrt(math.Abs(float64(dev))))
	return time.Duration(mean), time.Duration(dev), nil
}
RepetitionDurationStats extracts some duration stats by repeatedly execution
and measuring runtime. Returns the mean and deviation of the run duration of
the provided function. If an error is return by the function it will shortcut
the execution and return just the error.
package runtime
import (
	"errors"
	"fmt"
	"math"
	"sync"
	"time"
)
var timeNow = time.Now
func TrackDuration(f func() error) (time.Duration, error) {
	ts := timeNow()
	err := f()
	d := timeNow().Sub(ts)
	return d, err
}