MCPcopy
hub / github.com/perkeep/perkeep / BenchmarkLocationPredicate

Function BenchmarkLocationPredicate

pkg/search/query_test.go:2158–2233  ·  view source on GitHub ↗

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.

(b *testing.B)

Source from the content-addressed store, hash-verified

2156// It populates the corpus with enough fake foursquare checkins/venues and
2157// twitter locations to look realistic.
2158func BenchmarkLocationPredicate(b *testing.B) {
2159 b.ReportAllocs()
2160 testQueryTypes(b, corpusTypeOnly, func(qt *queryTest) {
2161 id := qt.id
2162
2163 var n int
2164 newPn := func() blob.Ref {
2165 n++
2166 return id.NewPlannedPermanode(fmt.Sprint(n))
2167 }
2168
2169 // create (~700) venues all over the world, and mark 25% of them as places we've been to
2170 venueIdx := 0
2171 for long := -180.0; long < 180.0; long += 10.0 {
2172 for lat := -90.0; lat < 90.0; lat += 10.0 {
2173 pn := newPn()
2174 id.SetAttribute(pn, "camliNodeType", "foursquare.com:venue")
2175 id.SetAttribute(pn, "latitude", fmt.Sprintf("%f", lat))
2176 id.SetAttribute(pn, "longitude", fmt.Sprintf("%f", long))
2177 if venueIdx%4 == 0 {
2178 qn := newPn()
2179 id.SetAttribute(qn, "camliNodeType", "foursquare.com:checkin")
2180 id.SetAttribute(qn, "foursquareVenuePermanode", pn.String())
2181 }
2182 venueIdx++
2183 }
2184 }
2185
2186 // create 3K tweets, all with locations
2187 lat := 45.18
2188 long := 5.72
2189 for i := 0; i < 3000; i++ {
2190 pn := newPn()
2191 id.SetAttribute(pn, "camliNodeType", "twitter.com:tweet")
2192 id.SetAttribute(pn, "latitude", fmt.Sprintf("%f", lat))
2193 id.SetAttribute(pn, "longitude", fmt.Sprintf("%f", long))
2194 lat += 0.01
2195 long += 0.01
2196 }
2197
2198 // create 5K additional permanodes, but no location. Just as "noise".
2199 for i := 0; i < 5000; i++ {
2200 newPn()
2201 }
2202
2203 // Create ~2600 photos all over the world.
2204 for long := -180.0; long < 180.0; long += 5.0 {
2205 for lat := -90.0; lat < 90.0; lat += 5.0 {
2206 br, _ := id.UploadFile("photo.jpg", exifFileContentLatLong(lat, long), time.Time{})
2207 pn := newPn()
2208 id.SetAttribute(pn, "camliContent", br.String())
2209 }
2210 }
2211
2212 h := qt.Handler()
2213 b.ResetTimer()
2214
2215 locations := []string{

Callers

nothing calls this directly

Calls 10

testQueryTypesFunction · 0.85
exifFileContentLatLongFunction · 0.85
NewPlannedPermanodeMethod · 0.80
SetAttributeMethod · 0.80
HandlerMethod · 0.80
FatalMethod · 0.80
LogfMethod · 0.80
QueryMethod · 0.65
StringMethod · 0.45
UploadFileMethod · 0.45

Tested by

no test coverage detected