From 4a9c1a9e6ce12c55c2be3e5a09233483e16187af Mon Sep 17 00:00:00 2001 From: George Angel Date: Sat, 10 Feb 2018 11:51:05 +0000 Subject: [PATCH] Add simple round trip benchmark --- Makefile | 3 +++ strongbox_test.go | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 7c810eb..89db925 100644 --- a/Makefile +++ b/Makefile @@ -7,3 +7,6 @@ build-test-image: test: build-test-image docker run --tmpfs /root:rw --rm $(IMAGE) + +bench: + go test -bench=. diff --git a/strongbox_test.go b/strongbox_test.go index d492da9..8b6277c 100644 --- a/strongbox_test.go +++ b/strongbox_test.go @@ -10,7 +10,8 @@ import ( ) var ( - priv []byte + priv []byte + plain = []byte("hello world. this is some plain text for testing") ) func TestMain(m *testing.M) { @@ -33,8 +34,6 @@ func testKeyLoader(string) ([]byte, error) { func TestMultipleClean(t *testing.T) { assert := assert.New(t) - plain := []byte("hello world. this is some plain text for testing") - var cleaned bytes.Buffer clean(bytes.NewReader(plain), &cleaned, "") @@ -47,8 +46,6 @@ func TestMultipleClean(t *testing.T) { func TestSmudgeAlreadyPlaintext(t *testing.T) { assert := assert.New(t) - plain := []byte("hello world. this is some plain text for testing") - var smudged bytes.Buffer smudge(bytes.NewReader(plain), &smudged, "") @@ -58,8 +55,6 @@ func TestSmudgeAlreadyPlaintext(t *testing.T) { func TestRoundTrip(t *testing.T) { assert := assert.New(t) - plain := []byte("hello world. this is some plain text for testing") - var cleaned bytes.Buffer clean(bytes.NewReader(plain), &cleaned, "") @@ -74,8 +69,6 @@ func TestRoundTrip(t *testing.T) { func TestDeterministic(t *testing.T) { assert := assert.New(t) - plain := []byte("hello world. this is some plain text for testing") - var cleaned1 bytes.Buffer clean(bytes.NewReader(plain), &cleaned1, "") @@ -84,3 +77,13 @@ func TestDeterministic(t *testing.T) { assert.Equal(string(cleaned1.Bytes()), string(cleaned2.Bytes())) } + +func BenchmarkRoundTripPlain(b *testing.B) { + for n := 0; n < b.N; n++ { + var cleaned bytes.Buffer + clean(bytes.NewReader(plain), &cleaned, "") + + var smudged bytes.Buffer + smudge(bytes.NewReader(cleaned.Bytes()), &smudged, "") + } +}