Skip to content

Instantly share code, notes, and snippets.

@barakmich
Created July 12, 2014 18:01
Show Gist options
  • Save barakmich/f75d452964a2efded879 to your computer and use it in GitHub Desktop.
Save barakmich/f75d452964a2efded879 to your computer and use it in GitHub Desktop.
var benchmarkQueries = []struct {
message string
query string
tag string
expect []string
}{
// Easy one to get us started. How quick is the most straightforward retrieval?
{
message: "name predicate",
query: `
g.V("Humphrey Bogart").In("name").All()
`,
expect: []string{":/en/humphrey_bogart"},
},
// Grunty queries.
// 2014-07-12: This one seems to return in ~20ms in memory;
// that's going to be measurably slower for every other backend.
{
message: "two large sets with no intersection",
query: `
function getId(x) { return g.V(x).In("name") }
var actor_to_film = g.M().In("/film/performance/actor").In("/film/film/starring")
getId("Oliver Hardy").Follow(actor_to_film).Out("name").Intersect(
getId("Mel Blanc").Follow(actor_to_film).Out("name")).All()
`,
expect: []string{},
},
// 2014-07-12: This one takes about 4 whole seconds in memory. This is a behemoth.
{
message: "three huge sets with small intersection",
query: `
function getId(x) { return g.V(x).In("name") }
var actor_to_film = g.M().In("/film/performance/actor").In("/film/film/starring")
var a = getId("Oliver Hardy").Follow(actor_to_film).FollowR(actor_to_film)
var b = getId("Mel Blanc").Follow(actor_to_film).FollowR(actor_to_film)
var c = getId("Billy Gilbert").Follow(actor_to_film).FollowR(actor_to_film)
seen = {}
a.Intersect(b).Intersect(c).ForEach(function (d) {
if (!(d.id in seen)) {
seen[d.id] = true;
g.Emit(d.id)
}
})
`,
expect: []string{":/en/billy_gilbert", ":/en/sterling_holloway"},
},
// This is more of an optimization problem that will get better over time. This takes a lot
// of wrong turns on the walk down to what is ultimately the name, but top AND has it easy
// as it has a fixed ID. Exercises Check().
{
message: "the helpless checker",
query: `
g.V().As("person").In("name").In().In().Out("name").Is("Casablanca").All()
`,
tag: "person",
expect: []string{
"Claude Rains",
"Conrad Veidt",
"Dooley Wilson",
"Helmut Dantine",
"Humphrey Bogart",
"Ingrid Bergman",
"John Qualen",
"Joy Page",
"Leonid Kinskey",
"Lou Marcelle",
"Madeleine LeBeau",
"Paul Henreid",
"Peter Lorre",
"Sydney Greenstreet",
"S.Z. Sakall"
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment