Esempio n. 1
0
func BenchmarkListGrid2DMoveIter(b *testing.B) {
	gen := rand.NewTimeSeed(rand.Xorshift)

	coords := make([]Point2D, 100*1000)
	rawFloats := make([]float64, 2*len(coords))
	gen.UniformAt(0.0, 1.0, rawFloats)
	for i := 0; i < len(coords); i++ {
		coords[i].X = rawFloats[2*i]
		coords[i].Y = rawFloats[2*i+1]
	}

	grid := NewListGrid2D(50, 1.0)
	grid.Insert(coords)

	rawFloats = make([]float64, b.N*2)
	coords = make([]Point2D, b.N)
	for i := 0; i < b.N; i++ {
		coords[i].X = rawFloats[2*i]
		coords[i].Y = rawFloats[2*i+1]
	}

	gen.UniformAt(0.0, 1.0, rawFloats)

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		grid.Move(i%len(grid.Points), &coords[i])
	}
}
Esempio n. 2
0
func BenchmarkSort(b *testing.B) {
	input := make([]float64, b.N)
	gen := rand.NewTimeSeed(rand.Xorshift)
	gen.UniformAt(0, 100, input)

	b.ResetTimer()

	sort.Float64s(input)
}
Esempio n. 3
0
func BenchmarkAddArrayTwice(b *testing.B) {
	input := make([]float64, b.N)
	gen := rand.NewTimeSeed(rand.Xorshift)
	gen.UniformAt(0, 100, input)

	hist, _ := new(Histogram).InitBounded([]float64{}, 1024, 0, 100)

	b.ResetTimer()
	hist.AddArray(input)
	hist.AddArray(input)
}
Esempio n. 4
0
func main() {
	if len(os.Args) != 3 {
		panic("")
	}

	trials, err := strconv.Atoi(os.Args[1])
	binNum, err := strconv.Atoi(os.Args[2])
	if err != nil {
		panic(err)
	}
	gen := rand.NewTimeSeed(rand.Default)

	angles := make([]float64, 2)
	line := geom.NewLine([]float64{0.5, 0.5, 0.5}, []float64{0.5, 0.5, 0.5})

	bins := make([]int, binNum)
	maxDist := math.Sqrt(3) * width

	for i := 0; i < trials; i++ {
		dist := muonDistance(angles, line, gen)
		binIdx := int(float64(binNum) * dist / maxDist)
		bins[binIdx]++
	}

	var percentBins vec.Vector = make([]float64, binNum)
	for i := 0; i < binNum; i++ {
		percentBins[i] = float64(bins[i]*binNum) / float64(trials)
	}

	binWidth := maxDist / float64(binNum)
	sum := 0.0
	measuredFluxSum := 0.0
	lowFluxSum := 0.0
	fmt.Printf("%15s %15s %15s %15s\n",
		"# dist [cm]", "E [MeV]", "prob density", "prob integral")
	for i := binNum - 1; i >= 0; i-- {
		sum += percentBins[i] / float64(binNum)
		x := binWidth * (float64(i) + 0.5)
		E := cmToMeV(x)
		flux := MeVToFlux(E)

		measuredFluxSum += sum * flux * binWidth
		if E < 110 {
			lowFluxSum += flux * binWidth
		}

		fmt.Printf("%15.6g %15.6g %15.6g %15.6g\n",
			x, E, percentBins[i], sum)
	}
	println("Full range measured flux:", measuredFluxSum)
	println("Actual in-range flux:", lowFluxSum)
	println("Flux ratio:", measuredFluxSum/lowFluxSum)
}
Esempio n. 5
0
func BenchmarkListGrid2DInsertSingleton(b *testing.B) {
	gen := rand.NewTimeSeed(rand.Xorshift)
	grid := NewListGrid2D(50, 1.0)

	rawFloats := make([]float64, b.N*2)
	inSlice := make([]Point2D, 1)
	gen.UniformAt(0.0, 1.0, rawFloats)

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		inSlice[0].X = rawFloats[i*2]
		inSlice[0].Y = rawFloats[i*2+1]
		grid.Insert(inSlice)
	}
}
Esempio n. 6
0
func BenchmarkListGrid2DInsertCacheMiss(b *testing.B) {
	gen := rand.NewTimeSeed(rand.Xorshift)
	grid := NewListGrid2D(1000, 1.0)

	coords := make([]Point2D, b.N)
	rawFloats := make([]float64, b.N*2)
	gen.UniformAt(0.0, 1.0, rawFloats)
	for i := 0; i < b.N; i++ {
		coords[i].X = rawFloats[2*i]
		coords[i].Y = rawFloats[2*i+1]
	}

	b.ResetTimer()

	grid.Insert(coords)
}