From 9990d7c9fbfe54c282013472a9d26264bacefc1c Mon Sep 17 00:00:00 2001 From: Alexandre Cesaro Date: Sat, 25 Jul 2015 19:01:46 +0200 Subject: [PATCH] Improved the benchmark --- message_test.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/message_test.go b/message_test.go index 4787db8..0553382 100644 --- a/message_test.go +++ b/message_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/base64" "io" + "io/ioutil" "path/filepath" "regexp" "strconv" @@ -600,12 +601,10 @@ func testFile(name string) *File { } func BenchmarkFull(b *testing.B) { - buf := new(bytes.Buffer) - emptyFunc := func(from string, to []string, m io.WriterTo) error { - m.WriteTo(buf) - buf.Reset() - return nil - } + discardFunc := SendFunc(func(from string, to []string, m io.WriterTo) error { + _, err := m.WriteTo(ioutil.Discard) + return err + }) m := NewMessage() b.ResetTimer() @@ -622,7 +621,7 @@ func BenchmarkFull(b *testing.B) { m.Attach(testFile("benchmark.txt")) m.Embed(testFile("benchmark.jpg")) - if err := Send(SendFunc(emptyFunc), m); err != nil { + if err := Send(discardFunc, m); err != nil { panic(err) } m.Reset()