Skip to content

Commit

Permalink
Merge pull request #28 from uw-labs/benchmarks
Browse files Browse the repository at this point in the history
Add simple round trip benchmark
  • Loading branch information
george-angel authored Feb 12, 2018
2 parents f3bfd66 + 4a9c1a9 commit ce3c714
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ build-test-image:

test: build-test-image
docker run --tmpfs /root:rw --rm $(IMAGE)

bench:
go test -bench=.
21 changes: 12 additions & 9 deletions strongbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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, "")

Expand All @@ -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, "")

Expand All @@ -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, "")

Expand All @@ -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, "")

Expand All @@ -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, "")
}
}

0 comments on commit ce3c714

Please sign in to comment.