mirror of https://github.com/gorilla/websocket.git
benchmarks for write with compression enabled/disabled
This commit is contained in:
parent
17634340a8
commit
34e053563d
|
@ -2,7 +2,9 @@ package websocket
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -29,3 +31,36 @@ func TestTruncWriter(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func textMessages(num int) [][]byte {
|
||||
messages := make([][]byte, num)
|
||||
for i := 0; i < num; i++ {
|
||||
msg := fmt.Sprintf("planet: %d, country: %d, city: %d, street: %d", i, i, i, i)
|
||||
messages[i] = []byte(msg)
|
||||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
func BenchmarkWriteNoCompression(b *testing.B) {
|
||||
w := ioutil.Discard
|
||||
c := newConn(fakeNetConn{Reader: nil, Writer: w}, false, 1024, 1024)
|
||||
messages := textMessages(100)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.WriteMessage(TextMessage, messages[i%len(messages)])
|
||||
}
|
||||
b.ReportAllocs()
|
||||
}
|
||||
|
||||
func BenchmarkWriteWithCompression(b *testing.B) {
|
||||
w := ioutil.Discard
|
||||
c := newConn(fakeNetConn{Reader: nil, Writer: w}, false, 1024, 1024)
|
||||
messages := textMessages(100)
|
||||
c.enableWriteCompression = true
|
||||
c.newCompressionWriter = compressNoContextTakeover
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.WriteMessage(TextMessage, messages[i%len(messages)])
|
||||
}
|
||||
b.ReportAllocs()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue