Commit 61c70837 authored by acud's avatar acud Committed by GitHub

add basic pipeline benchmarks (#836)

* add basic pipeline/splitter benchmarks
parent f8843d15
......@@ -7,8 +7,10 @@ package builder_test
import (
"bytes"
"context"
"crypto/rand"
"encoding/hex"
"fmt"
"strconv"
"testing"
"github.com/ethersphere/bee/pkg/file/pipeline/builder"
......@@ -76,3 +78,65 @@ func TestAllVectors(t *testing.T) {
})
}
}
/*
go test -v -bench=. -run Bench -benchmem
goos: linux
goarch: amd64
pkg: github.com/ethersphere/bee/pkg/file/pipeline/builder
BenchmarkPipeline
BenchmarkPipeline/1000-bytes
BenchmarkPipeline/1000-bytes-4 14475 75170 ns/op 63611 B/op 333 allocs/op
BenchmarkPipeline/10000-bytes
BenchmarkPipeline/10000-bytes-4 2775 459275 ns/op 321825 B/op 1826 allocs/op
BenchmarkPipeline/100000-bytes
BenchmarkPipeline/100000-bytes-4 334 3523558 ns/op 1891672 B/op 11994 allocs/op
BenchmarkPipeline/1000000-bytes
BenchmarkPipeline/1000000-bytes-4 36 33140883 ns/op 17745116 B/op 114170 allocs/op
BenchmarkPipeline/10000000-bytes
BenchmarkPipeline/10000000-bytes-4 4 304759595 ns/op 175378648 B/op 1135082 allocs/op
BenchmarkPipeline/100000000-bytes
BenchmarkPipeline/100000000-bytes-4 1 3064439098 ns/op 1751509528 B/op 11342736 allocs/op
PASS
ok github.com/ethersphere/bee/pkg/file/pipeline/builder 17.599s
*/
func BenchmarkPipeline(b *testing.B) {
for _, count := range []int{
1000, // 1k
10000, // 10 k
100000, // 100 k
1000000, // 1 mb
10000000, // 10 mb
100000000, // 100 mb
} {
b.Run(strconv.Itoa(count)+"-bytes", func(b *testing.B) {
for n := 0; n < b.N; n++ {
benchmarkPipeline(b, count)
}
})
}
}
func benchmarkPipeline(b *testing.B, count int) {
b.StopTimer()
m := mock.NewStorer()
p := builder.NewPipelineBuilder(context.Background(), m, storage.ModePutUpload, false)
data := make([]byte, count)
_, err := rand.Read(data)
if err != nil {
b.Fatal(err)
}
b.StartTimer()
_, err = p.Write(data)
if err != nil {
b.Fatal(err)
}
_, err = p.Sum()
if err != nil {
b.Fatal(err)
}
}
......@@ -7,6 +7,8 @@ package splitter_test
import (
"bytes"
"context"
"crypto/rand"
"strconv"
"testing"
"time"
......@@ -181,3 +183,63 @@ func TestUnalignedSplit(t *testing.T) {
t.Fatal("timeout")
}
}
/*
go test -v -bench=. -run Bench -benchmem
goos: linux
goarch: amd64
pkg: github.com/ethersphere/bee/pkg/file/splitter
BenchmarkSplitter
BenchmarkSplitter/1000-bytes
BenchmarkSplitter/1000-bytes-4 12667 95965 ns/op 154870 B/op 367 allocs/op
BenchmarkSplitter/10000-bytes
BenchmarkSplitter/10000-bytes-4 2808 418753 ns/op 369764 B/op 1624 allocs/op
BenchmarkSplitter/100000-bytes
BenchmarkSplitter/100000-bytes-4 349 3342003 ns/op 2042891 B/op 11810 allocs/op
BenchmarkSplitter/1000000-bytes
BenchmarkSplitter/1000000-bytes-4 33 30905753 ns/op 18825910 B/op 113721 allocs/op
BenchmarkSplitter/10000000-bytes
BenchmarkSplitter/10000000-bytes-4 4 295615658 ns/op 186417904 B/op 1132527 allocs/op
BenchmarkSplitter/100000000-bytes
BenchmarkSplitter/100000000-bytes-4 1 2972826021 ns/op 1861374352 B/op 11321235 allocs/op
PASS
ok github.com/ethersphere/bee/pkg/file/splitter 22.476s
*/
func BenchmarkSplitter(b *testing.B) {
for _, count := range []int{
1000, // 1k
10000, // 10 k
100000, // 100 k
1000000, // 1 mb
10000000, // 10 mb
100000000, // 100 mb
} {
b.Run(strconv.Itoa(count)+"-bytes", func(b *testing.B) {
for n := 0; n < b.N; n++ {
benchmarkSplitter(b, count)
}
})
}
}
func benchmarkSplitter(b *testing.B, count int) {
b.StopTimer()
m := mock.NewStorer()
s := splitter.NewSimpleSplitter(m, storage.ModePutUpload)
data := make([]byte, count)
_, err := rand.Read(data)
if err != nil {
b.Fatal(err)
}
testDataReader := file.NewSimpleReadCloser(data)
b.StartTimer()
_, err = s.Split(context.Background(), testDataReader, int64(len(data)), false)
if err != nil {
b.Fatal(err)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment