Exemplo n.º 1
0
func BenchmarkRandomInBound1000Naive(b *testing.B) {
	r := rand.New(rand.NewSource(43))

	var pointers []geo.Pointer
	for i := 0; i < 1000; i++ {
		pointers = append(pointers, geo.NewPoint(r.Float64(), r.Float64()))
	}

	b.ReportAllocs()
	b.ResetTimer()

	var near []geo.Pointer
	for i := 0; i < b.N; i++ {
		p := geo.NewPoint(r.Float64(), r.Float64())
		b := geo.NewBoundFromPoints(p, p).Pad(0.1)

		near = near[:0]
		for _, p := range pointers {
			if b.Contains(p.Point()) {
				near = append(near, p)
			}
		}

		_ = len(near)
	}
}