Пример #1
0
func ExampleNewStrider() {
	data := stat.Float64Slice{
		.0421, .0941, .1064, .0242,
		.1331, .0773, .0243, .0815,
		.1186, .0356, .0728, .0999,
		.0614, .0479}
	strider := stat.NewStrider(data, 4)
	fmt.Printf("mean data is %.4f\n", stat.Mean(data))
	fmt.Printf("mean strider is %.4f\n", stat.Mean(strider))
	// Output:
	// mean data is 0.0728
	// mean strider is 0.0979
}
Пример #2
0
func main() {
	flag.Parse()

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}

		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	log.Print("NumCPU: ", runtime.NumCPU())
	log.Print("GOMAXPROCS: ", runtime.GOMAXPROCS(-1))

	metrics = make(stat.IntSlice, *sampleSize)

	cfg, err := os.Open(*fixconfig)
	if err != nil {
		log.Fatal(err)
	}

	appSettings, err := quickfix.ParseSettings(cfg)
	if err != nil {
		log.Fatal(err)
	}

	logFactory := quickfix.NewNullLogFactory()
	storeFactory := quickfix.NewMemoryStoreFactory()

	acceptor, err := quickfix.NewAcceptor(app, storeFactory, appSettings, logFactory)
	if err != nil {
		log.Fatal(err)
	}
	if err = acceptor.Start(); err != nil {
		log.Fatal(err)
	}

	<-allDone
	elapsed := time.Since(t0)

	metricsUS := make(stat.Float64Slice, *sampleSize)
	for i, durationNS := range metrics {
		metricsUS[i] = float64(durationNS) / 1000.0
	}

	mean := stat.Mean(metricsUS)
	max, maxIndex := stat.Max(metricsUS)
	stdev := stat.Sd(metricsUS)

	log.Printf("Sample mean is %g us", mean)
	log.Printf("Sample max is %g us (%v)", max, maxIndex)
	log.Printf("Standard Dev is %g us", stdev)
	log.Printf("Processed %d msg in %v [effective rate: %.4f msg/s]", count, elapsed, float64(count)/float64(elapsed)*float64(time.Second))
}
Пример #3
0
func main() {
	flag.Parse()
	if *cpuprofile != "" {
		defer pprof.StopCPUProfile()
	}

	log.Print("NumCPU: ", runtime.NumCPU())
	log.Print("GOMAXPROCS: ", runtime.GOMAXPROCS(-1))

	metrics = make(stat.IntSlice, *sampleSize)

	cfg, err := os.Open(*fixconfig)
	if err != nil {
		log.Fatal(err)
	}

	appSettings, err := quickfix.ParseSettings(cfg)
	if err != nil {
		log.Fatal(err)
	}

	logFactory := quickfix.NewNullLogFactory()

	acceptor, err := quickfix.NewAcceptor(app, appSettings, logFactory)
	if err != nil {
		log.Fatal(err)
	}
	if err = acceptor.Start(); err != nil {
		log.Fatal(err)
	}

	<-allDone

	metricsUS := make(stat.Float64Slice, *sampleSize)
	for i, durationNS := range metrics {
		metricsUS[i] = float64(durationNS) / 1000.0
	}

	mean := stat.Mean(metricsUS)
	max, maxIndex := stat.Max(metricsUS)
	stdev := stat.Sd(metricsUS)

	log.Printf("Sample mean is %g us", mean)
	log.Printf("Sample max is %g us (%v)", max, maxIndex)
	log.Printf("Standard Dev is %g us", stdev)
}
Пример #4
0
func closeToMean(allnames []string, maxDist float64) (f Filter, mean, stdev float64) {
	data := make(stat.IntSlice, len(allnames))
	for i, name := range allnames {
		data[i] = int64(len(name))
	}

	mean = stat.Mean(data)
	stdev = stat.SdMean(data, mean)

	maxMean := int(mean + stdev*maxDist)

	f = func(name string) error {
		diff := float64(len(name)) - mean
		dist := diff / stdev

		if dist > maxDist {
			return fmt.Errorf("This package name is %.1f std.dev. longer than normal."+
				" It should be at most %d characters long.", dist, maxMean)
		}
		return nil
	}
	return
}
Пример #5
0
func ExampleMean() {
	data := stat.Float64Slice{17.2, 18.1, 16.5, 18.3, 12.6}
	mean := stat.Mean(data)
	fmt.Printf("The sample mean is %g", mean)
	// Output: The sample mean is 16.54
}