Last active
October 13, 2015 03:28
-
-
Save xtaci/be8e31a770e5cd502b6e to your computer and use it in GitHub Desktop.
rtree test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rtree | |
import ( | |
"github.com/dhconnelly/rtreego" | |
"math/rand" | |
"testing" | |
"time" | |
) | |
const ( | |
KTV = iota | |
HOTEL | |
) | |
const ( | |
NEW = iota | |
FIVE_YEARS | |
TEN_YEARS | |
TWENTY_YEARS | |
) | |
var tol = 0.01 | |
type Thing struct { | |
location rtreego.Point | |
name string | |
} | |
func (t *Thing) Bounds() *rtreego.Rect { | |
return t.location.ToRect(tol) | |
} | |
var ( | |
rt *rtreego.Rtree | |
) | |
func init() { | |
rand.Seed(time.Now().Unix()) | |
rt = rtreego.NewTree(4, 10, 20) | |
const N = 10000 | |
for i := 0; i < N; i++ { | |
rt.Insert(&Thing{rtreego.Point{rand.Float64() * N, rand.Float64() * N, HOTEL, float64(i % 4)}, "汉庭"}) | |
} | |
for i := 0; i < N; i++ { | |
rt.Insert(&Thing{rtreego.Point{rand.Float64() * N, rand.Float64() * N, KTV, float64(i % 4)}, "天上人间"}) | |
} | |
} | |
func BenchmarkRtree(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
bb, _ := rtreego.NewRect(rtreego.Point{0, 0, HOTEL, FIVE_YEARS}, []float64{1000, 1000, 0.1, 0.1}) | |
rt.SearchIntersect(bb) | |
bb, _ = rtreego.NewRect(rtreego.Point{0, 0, KTV, TEN_YEARS}, []float64{1000, 1000, 0.1, 0.1}) | |
rt.SearchIntersect(bb) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment