Skip to content

Commit

Permalink
update testData
Browse files Browse the repository at this point in the history
  • Loading branch information
lxzan committed Jul 30, 2023
1 parent 936a497 commit f520fbe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ test:
go test -count 1 -timeout 30s -run ^Test ./...

bench:
go test -benchmem -bench ^Benchmark github.com/lxzan/gws

build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/gws-linux-amd64 github.com/lxzan/gws/examples/testsuite
go test -benchmem -run=^$$ -bench . github.com/lxzan/gws

cover:
go test -coverprofile=./bin/cover.out --cover ./...
1 change: 1 addition & 0 deletions assets/github.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"current_user_url":"https://api.github.com/user","current_user_authorizations_html_url":"https://github.com/settings/connections/applications{/client_id}","authorizations_url":"https://api.github.com/authorizations","code_search_url":"https://api.github.com/search/code?q={query}{&page,per_page,sort,order}","commit_search_url":"https://api.github.com/search/commits?q={query}{&page,per_page,sort,order}","emails_url":"https://api.github.com/user/emails","emojis_url":"https://api.github.com/emojis","events_url":"https://api.github.com/events","feeds_url":"https://api.github.com/feeds","followers_url":"https://api.github.com/user/followers","following_url":"https://api.github.com/user/following{/target}","gists_url":"https://api.github.com/gists{/gist_id}","hub_url":"https://api.github.com/hub","issue_search_url":"https://api.github.com/search/issues?q={query}{&page,per_page,sort,order}","issues_url":"https://api.github.com/issues","keys_url":"https://api.github.com/user/keys","label_search_url":"https://api.github.com/search/labels?q={query}&repository_id={repository_id}{&page,per_page}","notifications_url":"https://api.github.com/notifications","organization_url":"https://api.github.com/orgs/{org}","organization_repositories_url":"https://api.github.com/orgs/{org}/repos{?type,page,per_page,sort}","organization_teams_url":"https://api.github.com/orgs/{org}/teams","public_gists_url":"https://api.github.com/gists/public","rate_limit_url":"https://api.github.com/rate_limit","repository_url":"https://api.github.com/repos/{owner}/{repo}","repository_search_url":"https://api.github.com/search/repositories?q={query}{&page,per_page,sort,order}","current_user_repositories_url":"https://api.github.com/user/repos{?type,page,per_page,sort}","starred_url":"https://api.github.com/user/starred{/owner}{/repo}","starred_gists_url":"https://api.github.com/gists/starred","topic_search_url":"https://api.github.com/search/topics?q={query}{&page,per_page}","user_url":"https://api.github.com/users/{user}","user_organizations_url":"https://api.github.com/user/orgs","user_repositories_url":"https://api.github.com/users/{user}/repos{?type,page,per_page,sort}","user_search_url":"https://api.github.com/search/users?q={query}{&page,per_page,sort,order}"}
21 changes: 13 additions & 8 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import (
"bufio"
"bytes"
"compress/flate"
_ "embed"
"encoding/binary"
klauspost "github.com/klauspost/compress/flate"
"github.com/lxzan/gws/internal"
"net"
"testing"
)

//go:embed assets/github.json
var githubData []byte

type benchConn struct {
net.TCPConn
}
Expand All @@ -27,21 +31,22 @@ func BenchmarkConn_WriteMessage(b *testing.B) {
config: upgrader.option.getConfig(),
}
for i := 0; i < b.N; i++ {
_ = conn.WriteMessage(OpcodeText, testdata)
_ = conn.WriteMessage(OpcodeText, githubData)
}
})

b.Run("compress enabled", func(b *testing.B) {
var upgrader = NewUpgrader(&BuiltinEventHandler{}, &ServerOption{
CompressEnabled: true,
CompressorNum: 64,
})
var conn = &Conn{
conn: &benchConn{},
compressEnabled: true,
config: upgrader.option.getConfig(),
}
for i := 0; i < b.N; i++ {
_ = conn.WriteMessage(OpcodeText, testdata)
_ = conn.WriteMessage(OpcodeText, githubData)
}
})
}
Expand All @@ -54,7 +59,7 @@ func BenchmarkConn_ReadMessage(b *testing.B) {
conn: &benchConn{},
config: upgrader.option.getConfig(),
}
var buf, _, _ = conn1.genFrame(OpcodeText, testdata)
var buf, _, _ = conn1.genFrame(OpcodeText, githubData)

var reader = bytes.NewBuffer(buf.Bytes())
var conn2 = &Conn{
Expand All @@ -79,7 +84,7 @@ func BenchmarkConn_ReadMessage(b *testing.B) {
compressEnabled: true,
config: upgrader.option.getConfig(),
}
var buf, _, _ = conn1.genFrame(OpcodeText, testdata)
var buf, _, _ = conn1.genFrame(OpcodeText, githubData)

var reader = bytes.NewBuffer(buf.Bytes())
var conn2 = &Conn{
Expand All @@ -100,8 +105,8 @@ func BenchmarkConn_ReadMessage(b *testing.B) {

func BenchmarkStdCompress(b *testing.B) {
fw, _ := flate.NewWriter(nil, flate.BestSpeed)
contents := testdata
buffer := bytes.NewBuffer(make([]byte, len(testdata)))
contents := githubData
buffer := bytes.NewBuffer(make([]byte, len(githubData)))
for i := 0; i < b.N; i++ {
buffer.Reset()
fw.Reset(buffer)
Expand All @@ -112,8 +117,8 @@ func BenchmarkStdCompress(b *testing.B) {

func BenchmarkKlauspostCompress(b *testing.B) {
fw, _ := klauspost.NewWriter(nil, flate.BestSpeed)
contents := testdata
buffer := bytes.NewBuffer(make([]byte, len(testdata)))
contents := githubData
buffer := bytes.NewBuffer(make([]byte, len(githubData)))
for i := 0; i < b.N; i++ {
buffer.Reset()
fw.Reset(buffer)
Expand Down

0 comments on commit f520fbe

Please sign in to comment.