mirror of https://github.com/perkeep/perkeep.git
Merge "pkg/search: benchmark location queries"
This commit is contained in:
commit
6b7e32d927
|
@ -1579,3 +1579,86 @@ func BenchmarkQueryPermanodeLocation(b *testing.B) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
// BenchmarkLocationPredicate aims at measuring the impact of
|
||||
// https://camlistore-review.googlesource.com/8049
|
||||
// ( + https://camlistore-review.googlesource.com/8649)
|
||||
// on location queries.
|
||||
// It populates the corpus with enough fake foursquare checkins/venues and
|
||||
// twitter locations to look realistic.
|
||||
func BenchmarkLocationPredicate(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
testQueryTypes(b, corpusTypeOnly, func(qt *queryTest) {
|
||||
id := qt.id
|
||||
|
||||
var n int
|
||||
newPn := func() blob.Ref {
|
||||
n++
|
||||
return id.NewPlannedPermanode(fmt.Sprint(n))
|
||||
}
|
||||
|
||||
// create (~700) venues all over the world, and mark 25% of them as places we've been to
|
||||
venueIdx := 0
|
||||
for long := -180; long < 180; long += 10 {
|
||||
for lat := -90; lat < 90; lat += 10 {
|
||||
pn := newPn()
|
||||
id.SetAttribute(pn, "camliNodeType", "foursquare.com:venue")
|
||||
id.SetAttribute(pn, "latitude", fmt.Sprintf("%f", lat))
|
||||
id.SetAttribute(pn, "longitude", fmt.Sprintf("%f", long))
|
||||
if venueIdx%4 == 0 {
|
||||
qn := newPn()
|
||||
id.SetAttribute(qn, "camliNodeType", "foursquare.com:checkin")
|
||||
id.SetAttribute(qn, "foursquareVenuePermanode", pn.String())
|
||||
}
|
||||
venueIdx++
|
||||
}
|
||||
}
|
||||
|
||||
// create 3K tweets, all with locations
|
||||
lat := 45.18
|
||||
long := 5.72
|
||||
for i := 0; i < 3000; i++ {
|
||||
pn := newPn()
|
||||
id.SetAttribute(pn, "camliNodeType", "twitter.com:tweet")
|
||||
id.SetAttribute(pn, "latitude", fmt.Sprintf("%f", lat))
|
||||
id.SetAttribute(pn, "longitude", fmt.Sprintf("%f", long))
|
||||
lat += 0.01
|
||||
long += 0.01
|
||||
}
|
||||
|
||||
// create 5K additional permanodes, but no location. Just as "noise".
|
||||
for i := 0; i < 5000; i++ {
|
||||
newPn()
|
||||
}
|
||||
|
||||
// TODO(attila): add permanodes with EXIFed camliContent.
|
||||
|
||||
h := qt.Handler()
|
||||
b.ResetTimer()
|
||||
|
||||
// TODO(attila): add a geocode Cache so we don't hit the
|
||||
// (random?) google geocode API errors.
|
||||
|
||||
// TODO(mpl): investigate whether it's normal that we don't find
|
||||
// any permanodes in e.g. Canada (no tweets is expected, but no 4sq
|
||||
// seems indeed a bit odd).
|
||||
|
||||
locations := []string{
|
||||
"canada", "scotland", "france", "sweden", "germany", "poland", "russia", "algeria", "congo", "china", "india", "australia", "mexico", "brazil", "argentina",
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, loc := range locations {
|
||||
req := &SearchQuery{
|
||||
Expression: "loc:" + loc,
|
||||
Limit: -1,
|
||||
}
|
||||
resp, err := h.Query(req)
|
||||
if err != nil {
|
||||
qt.t.Fatal(err)
|
||||
}
|
||||
b.Logf("found %d permanodes in %v", len(resp.Blobs), loc)
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue