func (ts timeSlice) cumulative() time.Duration {
	var total time.Duration
	for _, t := range ts {
		total += t
	}
	return total
}
These should be self-explanatory:
package tachymeter
import (
	"fmt"
	"math"
	"sort"
	"sync/atomic"
	"time"
)
func (m *Tachymeter) Calc() *Metrics {
	metrics := &Metrics{}
	if atomic.LoadUint64(&m.Count) == 0 {
		return metrics
	}
	m.Lock()
	metrics.Samples = int(math.Min(float64(atomic.LoadUint64(&m.Count)), float64(m.Size)))
	metrics.Count = int(atomic.LoadUint64(&m.Count))
	times := make(timeSlice, metrics.Samples)
	copy(times, m.Times[:metrics.Samples])
	sort.Sort(times)
	metrics.Time.Cumulative = times.cumulative()
	var rateTime float64
	if m.WallTime != 0 {
		rateTime = float64(metrics.Count) / float64(m.WallTime)
	} else {
		rateTime = float64(metrics.Samples) / float64(metrics.Time.Cumulative)
	}
	metrics.Rate.Second = rateTime * 1e9
	m.Unlock()
	metrics.Time.Avg = times.avg()
	metrics.Time.HMean = times.hMean()
	metrics.Time.P50 = times[times.Len()/2]
	metrics.Time.P75 = times.p(0.75)
	metrics.Time.P95 = times.p(0.95)
	metrics.Time.P99 = times.p(0.99)
	metrics.Time.P999 = times.p(0.999)
	metrics.Time.Long5p = times.long5p()
	metrics.Time.Short5p = times.short5p()
	metrics.Time.Min = times.min()
	metrics.Time.Max = times.max()
	metrics.Time.Range = times.srange()
	metrics.Time.StdDev = times.stdDev()
	metrics.Histogram, metrics.HistogramBinSize = times.hgram(m.HBins)
	return metrics
}
func (ts timeSlice) hgram(b int) (*Histogram, time.Duration) {
	res := time.Duration(1000)
	interval := time.Duration(int64(ts.srange()) / int64(b))
	high := ts.min() + interval
	low := ts.min()
	max := ts.max()
	hgram := &Histogram{}
	pos := 1  
	bstring := fmt.Sprintf("%s - %s", low/res*res, high/res*res)
	bin := map[string]uint64{}
	for _, v := range ts {
		if v <= high {
			bin[bstring]++
		} else {
			*hgram = append(*hgram, bin)
			bin = map[string]uint64{}
			low = high + time.Nanosecond
			high += interval
			if pos == b-1 {
				high = max
			}
			bstring = fmt.Sprintf("%s - %s", low/res*res, high/res*res)
			bin[bstring]++
			pos++
		}
	}
	*hgram = append(*hgram, bin)
	return hgram, interval
}