mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 01:45:44 +03:00
Benchmark for rotator
BenchmarkRotator/1KB-8 200000 5572 ns/op BenchmarkRotator/2KB-8 200000 8338 ns/op BenchmarkRotator/4KB-8 100000 14246 ns/op BenchmarkRotator/8KB-8 50000 25279 ns/op BenchmarkRotator/16KB-8 30000 48602 ns/op BenchmarkRotator/32KB-8 20000 92159 ns/op BenchmarkRotator/64KB-8 10000 154766 ns/op BenchmarkRotator/128KB-8 5000 296872 ns/op BenchmarkRotator/256KB-8 3000 551793 ns/op
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
|
||||
const (
|
||||
// logBufferSize is the size of the buffer.
|
||||
logBufferSize = 32768
|
||||
logBufferSize = 32 * 1024
|
||||
|
||||
// bufferFlushDuration is the duration at which we flush the buffer.
|
||||
bufferFlushDuration = 100 * time.Millisecond
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -289,3 +290,48 @@ func TestFileRotator_PurgeOldFiles(t *testing.T) {
|
||||
t.Fatalf("%v", lastErr)
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkRotator(b *testing.B) {
|
||||
kb := 1024
|
||||
for _, inputSize := range []int{kb, 2 * kb, 4 * kb, 8 * kb, 16 * kb, 32 * kb, 64 * kb, 128 * kb, 256 * kb} {
|
||||
b.Run(fmt.Sprintf("%dKB", inputSize/kb), func(b *testing.B) {
|
||||
benchmarkRotatorWithInputSize(inputSize, b)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkRotatorWithInputSize(size int, b *testing.B) {
|
||||
var path string
|
||||
var err error
|
||||
if path, err = ioutil.TempDir("", pathPrefix); err != nil {
|
||||
b.Fatalf("test setup err: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
fr, err := NewFileRotator(path, baseFileName, 5, 1024*1024, logger)
|
||||
if err != nil {
|
||||
b.Fatalf("test setup err: %v", err)
|
||||
}
|
||||
b.ResetTimer()
|
||||
|
||||
// run the Fib function b.N times
|
||||
for n := 0; n < b.N; n++ {
|
||||
// Generate some input
|
||||
data := make([]byte, size)
|
||||
_, err := rand.Read(data)
|
||||
if err != nil {
|
||||
b.Fatalf("Error generating date: %v", err)
|
||||
}
|
||||
|
||||
// Insert random new lines
|
||||
for i := 0; i < 100; i++ {
|
||||
index := rand.Intn(size)
|
||||
data[index] = '\n'
|
||||
}
|
||||
|
||||
// Write the data
|
||||
if _, err := fr.Write(data); err != nil {
|
||||
b.Fatalf("Failed to write data: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user