Skip to content

Commit

Permalink
Refactor benchmark and add remove unexistent triples.
Browse files Browse the repository at this point in the history
  • Loading branch information
xllora committed Mar 19, 2016
1 parent f643f5f commit 710fa42
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 52 deletions.
39 changes: 7 additions & 32 deletions tools/benchmark/batteries/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,19 @@ import (
"fmt"

"github.com/google/badwolf/storage"
"github.com/google/badwolf/tools/benchmark/generator"
"github.com/google/badwolf/tools/benchmark/generator/graph"
"github.com/google/badwolf/tools/benchmark/generator/tree"
"github.com/google/badwolf/tools/benchmark/runtime"
"github.com/google/badwolf/triple"
"golang.org/x/net/context"
)

// getTreeGenerators returns the set of tree generators to use while creating
// benchmarks.
func getTreeGenerators(bFactors []int) ([]generator.Generator, error) {
var gens []generator.Generator
for _, b := range bFactors {
t, err := tree.New(b)
if err != nil {
return nil, err
}
gens = append(gens, t)
}
return gens, nil
}

// AddTreeTriplesBenchmark creates the benchmark
func AddTreeTriplesBenchmark(ctx context.Context, st storage.Store) ([]*runtime.BenchEntry, error) {
bFactors := []int{2, 200}
sizes := []int{10, 1000, 100000}
var trplSets [][]*triple.Triple
var ids []string
var gids []string
var gSizes []int
gs, err := getTreeGenerators(bFactors)
if err != nil {
return nil, err
Expand All @@ -61,6 +45,7 @@ func AddTreeTriplesBenchmark(ctx context.Context, st storage.Store) ([]*runtime.
trplSets = append(trplSets, ts)
ids = append(ids, fmt.Sprintf("tg branch_factor=%04d, size=%07d", bFactors[idx], s))
gids = append(gids, fmt.Sprintf("b%d_s%d", bFactors[idx], s))
gSizes = append(gSizes, s)
}
}
var bes []*runtime.BenchEntry
Expand All @@ -71,8 +56,9 @@ func AddTreeTriplesBenchmark(ctx context.Context, st storage.Store) ([]*runtime.
gID := fmt.Sprintf("add_tree_%s_r%d_i%d", gids[i], i, idxReps)
data := trplSets[i]
bes = append(bes, &runtime.BenchEntry{
BatteryID: "Add triples",
BatteryID: "Add non-existent triples",
ID: fmt.Sprintf("%s, reps=%02d", ids[i], r),
Triples: gSizes[i],
Reps: r,
Setup: func() error {
var err error
Expand All @@ -91,27 +77,14 @@ func AddTreeTriplesBenchmark(ctx context.Context, st storage.Store) ([]*runtime.
return bes, nil
}

// getGraphGenerators returns the set of tree generators to use while creating
// benchmarks.
func getGraphGenerators(nodes []int) ([]generator.Generator, error) {
var gens []generator.Generator
for _, b := range nodes {
t, err := graph.NewRandomGraph(b)
if err != nil {
return nil, err
}
gens = append(gens, t)
}
return gens, nil
}

// AddGraphTriplesBenchmark creates the benchmark
func AddGraphTriplesBenchmark(ctx context.Context, st storage.Store) ([]*runtime.BenchEntry, error) {
nodes := []int{317, 1000}
sizes := []int{10, 1000, 100000}
var trplSets [][]*triple.Triple
var ids []string
var gids []string
var gSizes []int
gs, err := getGraphGenerators(nodes)
if err != nil {
return nil, err
Expand All @@ -125,6 +98,7 @@ func AddGraphTriplesBenchmark(ctx context.Context, st storage.Store) ([]*runtime
trplSets = append(trplSets, ts)
ids = append(ids, fmt.Sprintf("rg nodes=%04d, size=%07d", nodes[idx], s))
gids = append(gids, fmt.Sprintf("n%d_s%d", nodes[idx], s))
gSizes = append(gSizes, s)
}
}
var bes []*runtime.BenchEntry
Expand All @@ -137,6 +111,7 @@ func AddGraphTriplesBenchmark(ctx context.Context, st storage.Store) ([]*runtime
bes = append(bes, &runtime.BenchEntry{
BatteryID: "Add triples",
ID: fmt.Sprintf("%s, reps=%02d", ids[i], r),
Triples: gSizes[i],
Reps: r,
Setup: func() error {
var err error
Expand Down
50 changes: 50 additions & 0 deletions tools/benchmark/batteries/generators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2016 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package batteries generates the benchmarks used for testing.
package batteries

import (
"github.com/google/badwolf/tools/benchmark/generator"
"github.com/google/badwolf/tools/benchmark/generator/graph"
"github.com/google/badwolf/tools/benchmark/generator/tree"
)

// getTreeGenerators returns the set of tree generators to use while creating
// benchmarks.
func getTreeGenerators(bFactors []int) ([]generator.Generator, error) {
var gens []generator.Generator
for _, b := range bFactors {
t, err := tree.New(b)
if err != nil {
return nil, err
}
gens = append(gens, t)
}
return gens, nil
}

// getGraphGenerators returns the set of tree generators to use while creating
// benchmarks.
func getGraphGenerators(nodes []int) ([]generator.Generator, error) {
var gens []generator.Generator
for _, b := range nodes {
t, err := graph.NewRandomGraph(b)
if err != nil {
return nil, err
}
gens = append(gens, t)
}
return gens, nil
}
131 changes: 131 additions & 0 deletions tools/benchmark/batteries/remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright 2016 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package batteries generates the benchmarks used for testing.
package batteries

import (
"fmt"

"github.com/google/badwolf/storage"
"github.com/google/badwolf/tools/benchmark/runtime"
"github.com/google/badwolf/triple"
"golang.org/x/net/context"
)

// RemoveTreeTriplesBenchmark creates the benchmark
func RemoveTreeTriplesBenchmark(ctx context.Context, st storage.Store) ([]*runtime.BenchEntry, error) {
bFactors := []int{2, 200}
sizes := []int{10, 1000, 100000}
var trplSets [][]*triple.Triple
var ids []string
var gids []string
var gSizes []int
gs, err := getTreeGenerators(bFactors)
if err != nil {
return nil, err
}
for idx, g := range gs {
for _, s := range sizes {
ts, err := g.Generate(s)
if err != nil {
return nil, err
}
trplSets = append(trplSets, ts)
ids = append(ids, fmt.Sprintf("tg branch_factor=%04d, size=%07d", bFactors[idx], s))
gids = append(gids, fmt.Sprintf("b%d_s%d", bFactors[idx], s))
gSizes = append(gSizes, s)
}
}
var bes []*runtime.BenchEntry
reps := []int{10}
for i, max := 0, len(ids); i < max; i++ {
for idxReps, r := range reps {
var g storage.Graph
gID := fmt.Sprintf("add_tree_%s_r%d_i%d", gids[i], i, idxReps)
data := trplSets[i]
bes = append(bes, &runtime.BenchEntry{
BatteryID: "Remove triples",
ID: fmt.Sprintf("%s, reps=%02d", ids[i], r),
Triples: gSizes[i],
Reps: r,
Setup: func() error {
var err error
g, err = st.NewGraph(ctx, gID)
return err
},
F: func() error {
return g.RemoveTriples(ctx, data)
},
TearDown: func() error {
return st.DeleteGraph(ctx, gID)
},
})
}
}
return bes, nil
}

// RemoveGraphTriplesBenchmark creates the benchmark
func RemoveGraphTriplesBenchmark(ctx context.Context, st storage.Store) ([]*runtime.BenchEntry, error) {
nodes := []int{317, 1000}
sizes := []int{10, 1000, 100000}
var trplSets [][]*triple.Triple
var ids []string
var gids []string
var gSizes []int
gs, err := getGraphGenerators(nodes)
if err != nil {
return nil, err
}
for idx, g := range gs {
for _, s := range sizes {
ts, err := g.Generate(s)
if err != nil {
return nil, err
}
trplSets = append(trplSets, ts)
ids = append(ids, fmt.Sprintf("rg nodes=%04d, size=%07d", nodes[idx], s))
gids = append(gids, fmt.Sprintf("n%d_s%d", nodes[idx], s))
gSizes = append(gSizes, s)
}
}
var bes []*runtime.BenchEntry
reps := []int{10}
for i, max := 0, len(ids); i < max; i++ {
for idxReps, r := range reps {
var g storage.Graph
gID := fmt.Sprintf("add_graph_%s_r%d_i%d", gids[i], i, idxReps)
data := trplSets[i]
bes = append(bes, &runtime.BenchEntry{
BatteryID: "Remove triples",
ID: fmt.Sprintf("%s, reps=%02d", ids[i], r),
Triples: gSizes[i],
Reps: r,
Setup: func() error {
var err error
g, err = st.NewGraph(ctx, gID)
return err
},
F: func() error {
return g.RemoveTriples(ctx, data)
},
TearDown: func() error {
return st.DeleteGraph(ctx, gID)
},
})
}
}
return bes, nil
}
4 changes: 4 additions & 0 deletions tools/benchmark/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func RepetitionDurationStats(reps int, setup, f, teardown func() error) (time.Du
type BenchEntry struct {
BatteryID string
ID string
Triples int
Reps int
Setup func() error
F func() error
Expand All @@ -96,6 +97,7 @@ type BenchEntry struct {
type BenchResult struct {
BatteryID string
ID string
Triples int
Err error
Mean time.Duration
StdDev time.Duration
Expand All @@ -110,6 +112,7 @@ func RunBenchmarkBatterySequentially(entries []*BenchEntry) []*BenchResult {
res = append(res, &BenchResult{
BatteryID: entry.BatteryID,
ID: entry.ID,
Triples: entry.Triples,
Err: err,
Mean: m,
StdDev: d,
Expand All @@ -136,6 +139,7 @@ func RunBenchmarkBatteryConcurrently(entries []*BenchEntry) []*BenchResult {
res = append(res, &BenchResult{
BatteryID: entry.BatteryID,
ID: entry.ID,
Triples: entry.Triples,
Err: err,
Mean: m,
StdDev: d,
Expand Down
Loading

0 comments on commit 710fa42

Please sign in to comment.