Skip to content
Snippets Groups Projects
Commit 9dd2df4c authored by Manish R Jain's avatar Manish R Jain
Browse files

Add benchmarks. Change the test data a bit.

parent eb4f0a0c
No related branches found
No related tags found
No related merge requests found
...@@ -28,14 +28,8 @@ import ( ...@@ -28,14 +28,8 @@ import (
"github.com/dgraph-io/dgraph/store" "github.com/dgraph-io/dgraph/store"
) )
func NewStore(t *testing.T) string { func NewStore() (string, error) {
path, err := ioutil.TempDir("", "storetest_") return ioutil.TempDir("", "storetest_")
if err != nil {
t.Error(err)
t.Fail()
return ""
}
return path
} }
var q0 = ` var q0 = `
...@@ -51,13 +45,19 @@ var q0 = ` ...@@ -51,13 +45,19 @@ var q0 = `
} }
` `
func TestQuery(t *testing.T) { func prepare() error {
pdir := NewStore(t) pdir, err := NewStore()
if err != nil {
return err
}
defer os.RemoveAll(pdir) defer os.RemoveAll(pdir)
ps := new(store.Store) ps := new(store.Store)
ps.Init(pdir) ps.Init(pdir)
mdir := NewStore(t) mdir, err := NewStore()
if err != nil {
return err
}
defer os.RemoveAll(mdir) defer os.RemoveAll(mdir)
ms := new(store.Store) ms := new(store.Store)
ms.Init(mdir) ms.Init(mdir)
...@@ -65,16 +65,21 @@ func TestQuery(t *testing.T) { ...@@ -65,16 +65,21 @@ func TestQuery(t *testing.T) {
f, err := os.Open("testdata.nq") f, err := os.Open("testdata.nq")
if err != nil { if err != nil {
t.Error(err) return err
return
} }
defer f.Close() defer f.Close()
count, err := handleRdfReader(f) _, err = handleRdfReader(f)
if err != nil { if err != nil {
return err
}
return nil
}
func TestQuery(t *testing.T) {
if err := prepare(); err != nil {
t.Error(err) t.Error(err)
return return
} }
t.Logf("Parsed %v RDFs", count)
// Parse GQL into internal query representation. // Parse GQL into internal query representation.
g, err := gql.Parse(q0) g, err := gql.Parse(q0)
...@@ -132,3 +137,53 @@ func TestQuery(t *testing.T) { ...@@ -132,3 +137,53 @@ func TestQuery(t *testing.T) {
} }
fmt.Println(string(js)) fmt.Println(string(js))
} }
var q1 = `
{
al(_xid_: alice) {
status
_xid_
follows {
status
_xid_
follows {
status
_xid_
follows {
_xid_
status
}
}
}
status
_xid_
}
}
`
func BenchmarkQuery(b *testing.B) {
if err := prepare(); err != nil {
b.Error(err)
return
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
g, err := gql.Parse(q1)
if err != nil {
b.Error(err)
return
}
ch := make(chan error)
go query.ProcessGraph(g, ch)
if err := <-ch; err != nil {
b.Error(err)
return
}
_, err = g.ToJson()
if err != nil {
b.Error(err)
return
}
}
}
<alice> <follows> <bob> . <alice> <follows> <bob> .
<bob> <follows> <fred> . <bob> <follows> <fred> .
<bob> <status> "cool_person" . <bob> <status> "I'm your Uncle Bob!" .
<charlie> <follows> <bob> . <charlie> <follows> <bob> .
<charlie> <follows> <dani> . <charlie> <follows> <dani> .
<dani> <follows> <bob> . <dani> <follows> <bob> .
<dani> <follows> <greg> . <dani> <follows> <greg> .
<dani> <status> "cool_person" . <dani> <status> "Smart Dani" .
<emily> <follows> <fred> . <emily> <follows> <fred> .
<fred> <follows> <greg> . <fred> <follows> <greg> .
<greg> <status> "cool_person" . <greg> <status> "Mr. Cool greg" .
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment