Improved the benchmark

This commit is contained in:
Alexandre Cesaro 2015-07-25 19:01:46 +02:00
parent 9bc424b2ec
commit 9990d7c9fb
1 changed files with 6 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"io" "io"
"io/ioutil"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv" "strconv"
@ -600,12 +601,10 @@ func testFile(name string) *File {
} }
func BenchmarkFull(b *testing.B) { func BenchmarkFull(b *testing.B) {
buf := new(bytes.Buffer) discardFunc := SendFunc(func(from string, to []string, m io.WriterTo) error {
emptyFunc := func(from string, to []string, m io.WriterTo) error { _, err := m.WriteTo(ioutil.Discard)
m.WriteTo(buf) return err
buf.Reset() })
return nil
}
m := NewMessage() m := NewMessage()
b.ResetTimer() b.ResetTimer()
@ -622,7 +621,7 @@ func BenchmarkFull(b *testing.B) {
m.Attach(testFile("benchmark.txt")) m.Attach(testFile("benchmark.txt"))
m.Embed(testFile("benchmark.jpg")) m.Embed(testFile("benchmark.jpg"))
if err := Send(SendFunc(emptyFunc), m); err != nil { if err := Send(discardFunc, m); err != nil {
panic(err) panic(err)
} }
m.Reset() m.Reset()