Skip to content

Commit

Permalink
Merge pull request #585 from matheusd/benchmark-release
Browse files Browse the repository at this point in the history
integration: Benchmark with/without release
  • Loading branch information
lthibault authored Aug 14, 2024
2 parents 202e2e7 + 9cb8be8 commit e51721e
Showing 1 changed file with 59 additions and 15 deletions.
74 changes: 59 additions & 15 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"io"
"math/rand"
"testing"
Expand Down Expand Up @@ -2223,7 +2224,7 @@ func TestFuzzedListOutOfBounds(t *testing.T) {
}
}

func benchmarkGrowth(b *testing.B, newArena func() capnp.Arena) {
func benchmarkGrowth(b *testing.B, newArena func() capnp.Arena, release bool) {
const (
fieldValue = "1234567" // carefully chosen to be word-padded

Expand All @@ -2235,7 +2236,7 @@ func benchmarkGrowth(b *testing.B, newArena func() capnp.Arena) {
b.SetBytes(totalSize)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, seg, err := capnp.NewMessage(newArena())
msg, seg, err := capnp.NewMessage(newArena())
if err != nil {
b.Fatal(err)
}
Expand All @@ -2252,23 +2253,46 @@ func benchmarkGrowth(b *testing.B, newArena func() capnp.Arena) {
b.Fatal(err)
}
}

if release {
msg.Release()
}
}
}

func BenchmarkGrowth_SingleSegment(b *testing.B) {
benchmarkGrowth(b, func() capnp.Arena { return capnp.SingleSegment(nil) })
}
func newSingleSegmentArena() capnp.Arena { return capnp.SingleSegment(nil) }
func newMultiSegmentArena() capnp.Arena { return capnp.MultiSegment(nil) }

func BenchmarkGrowth_MultiSegment(b *testing.B) {
benchmarkGrowth(b, func() capnp.Arena { return capnp.MultiSegment(nil) })
func BenchmarkGrowth(b *testing.B) {
tests := []struct {
name string
newArena func() capnp.Arena
}{{
name: "SingleSegment",
newArena: newSingleSegmentArena,
}, {
name: "MultiSegment",
newArena: newMultiSegmentArena,
}}

for _, release := range []bool{false, true} {
release := release
for i := range tests {
tc := tests[i]
name := fmt.Sprintf("%s/release=%v", tc.name, release)
b.Run(name, func(b *testing.B) {
benchmarkGrowth(b, tc.newArena, release)
})
}
}
}

func benchmarkSmallMessage(b *testing.B, newArena func() capnp.Arena) {
func benchmarkSmallMessage(b *testing.B, newArena func() capnp.Arena, release bool) {
const fieldValue = "1234567" // carefully chosen to be word-padded
b.SetBytes(8 * 9)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, seg, err := capnp.NewMessage(newArena())
msg, seg, err := capnp.NewMessage(newArena())
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -2299,13 +2323,33 @@ func benchmarkSmallMessage(b *testing.B, newArena func() capnp.Arena) {
if err := root.SetPtr(0, sub2.ToPtr()); err != nil {
b.Fatal(err)
}
}
}

func BenchmarkSmallMessage_SingleSegment(b *testing.B) {
benchmarkSmallMessage(b, func() capnp.Arena { return capnp.SingleSegment(nil) })
if release {
msg.Release()
}
}
}

func BenchmarkSmallMessage_MultiSegment(b *testing.B) {
benchmarkSmallMessage(b, func() capnp.Arena { return capnp.MultiSegment(nil) })
func BenchmarkSmallMessage(b *testing.B) {
tests := []struct {
name string
newArena func() capnp.Arena
}{{
name: "SingleSegment",
newArena: newSingleSegmentArena,
}, {
name: "MultiSegment",
newArena: newMultiSegmentArena,
}}

for _, release := range []bool{false, true} {
release := release
for i := range tests {
tc := tests[i]
name := fmt.Sprintf("%s/release=%v", tc.name, release)
b.Run(name, func(b *testing.B) {
benchmarkSmallMessage(b, tc.newArena, release)
})
}
}
}

0 comments on commit e51721e

Please sign in to comment.