mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Rather than use defer. It is only a tiny amount faster, but this function is frequently called. Before: $ go test -bench=BenchmarkSendQueue -benchtime=2s BenchmarkSendQueue-4 15901834 151 ns/op After: $ go test -bench=BenchmarkSendQueue -benchtime=2s BenchmarkSendQueue-4 15859948 147 ns/op https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40177
18 lines
413 B
Go
18 lines
413 B
Go
package turbotunnel
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Benchmark the ClientMap.SendQueue function. This is mainly measuring the cost
|
|
// of the mutex operations around the call to clientMapInner.SendQueue.
|
|
func BenchmarkSendQueue(b *testing.B) {
|
|
m := NewClientMap(1 * time.Hour)
|
|
id := NewClientID()
|
|
m.SendQueue(id) // populate the entry for id
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
m.SendQueue(id)
|
|
}
|
|
}
|