mirror of
https://github.com/fluffle/goirc
synced 2025-09-06 00:43:20 +00:00
Use make size hint when copying channels in Nick()
70% faster when using a high number of channels Old performance ``` $ go test ./state -bench=. goos: linux goarch: amd64 pkg: github.com/fluffle/goirc/state cpu: AMD Ryzen Threadripper PRO 3945WX 12-Cores BenchmarkNickSingleChan-24 15465226 76.35 ns/op BenchmarkNickManyChan-24 5738 195721 ns/op PASS ok github.com/fluffle/goirc/state 2.433s ``` new performance ``` $ go test ./state -bench=. goos: linux goarch: amd64 pkg: github.com/fluffle/goirc/state cpu: AMD Ryzen Threadripper PRO 3945WX 12-Cores BenchmarkNickSingleChan-24 15022640 79.13 ns/op BenchmarkNickManyChan-24 10000 115104 ns/op PASS ok github.com/fluffle/goirc/state 2.456s ```
This commit is contained in:
parent
2b7abdce8f
commit
8b460bc60f
2 changed files with 34 additions and 2 deletions
|
@ -1,6 +1,9 @@
|
|||
package state
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func compareNick(t *testing.T, nk *nick) {
|
||||
n := nk.Nick()
|
||||
|
@ -86,3 +89,30 @@ func TestNickParseModes(t *testing.T) {
|
|||
t.Errorf("Modes not flipped correctly by ParseModes.")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNickSingleChan(b *testing.B) {
|
||||
nk := newNick("test1")
|
||||
ch := newChannel("#test1")
|
||||
cp := new(ChanPrivs)
|
||||
nk.addChannel(ch, cp)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
nk.Nick()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNickManyChan(b *testing.B) {
|
||||
const numChans = 1000
|
||||
nk := newNick("test1")
|
||||
for i := 0; i < numChans; i++ {
|
||||
ch := newChannel(fmt.Sprintf("#test%d", i))
|
||||
cp := new(ChanPrivs)
|
||||
nk.addChannel(ch, cp)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
nk.Nick()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue