Skip to content

Commit

Permalink
Add benchmarks for inserting documents
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarsa committed Feb 26, 2016
1 parent d90005c commit 699256f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"sort"
"strconv"
"strings"
"testing"
"time"

. "gopkg.in/check.v1"
Expand Down Expand Up @@ -4125,3 +4126,46 @@ func (s *S) BenchmarkFindIterRaw(c *C) {
c.Assert(iter.Err(), IsNil)
c.Assert(i, Equals, c.N)
}

func BenchmarkInsertSingle(b *testing.B) {
session, err := mgo.Dial("localhost:40001")
if err != nil {
b.Fatal(err)
}
defer session.Close()

doc := bson.D{
{"A", strings.Repeat("*", 256)},
}
coll := session.DB("mydb").C("benchmarkcoll")
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := coll.Insert(doc)
if err != nil {
b.Fatal(err)
}
}
}

func BenchmarkInsertMultiple(b *testing.B) {
session, err := mgo.Dial("localhost:40001")
if err != nil {
b.Fatal(err)
}
defer session.Close()

docs := make([]interface{}, 100)
for i := range docs {
docs[i] = bson.D{
{"A", strings.Repeat("*", 256)},
}
}
coll := session.DB("mydb").C("benchmarkcoll")
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := coll.Insert(docs...)
if err != nil {
b.Fatal(err)
}
}
}

0 comments on commit 699256f

Please sign in to comment.