Skip to content

Commit 14172e5

Browse files
committed
Benchmark pure go masking algorithm separately from assembly
1 parent f5397ae commit 14172e5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

internal/thirdparty/frame_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ func gorillaMaskBytes(key [4]byte, pos int, b []byte) int
2626
//go:linkname mask nhooyr.io/websocket.mask
2727
func mask(key32 uint32, b []byte) int
2828

29+
//go:linkname maskGo nhooyr.io/websocket.maskGo
30+
func maskGo(key32 uint32, b []byte) int
31+
2932
func Benchmark_mask(b *testing.B) {
3033
sizes := []int{
3134
2,
@@ -54,7 +57,18 @@ func Benchmark_mask(b *testing.B) {
5457
},
5558

5659
{
57-
name: "nhooyr",
60+
name: "nhooyr-go",
61+
fn: func(b *testing.B, key [4]byte, p []byte) {
62+
key32 := binary.LittleEndian.Uint32(key[:])
63+
b.ResetTimer()
64+
65+
for i := 0; i < b.N; i++ {
66+
maskGo(key32, p)
67+
}
68+
},
69+
},
70+
{
71+
name: "wdvxdr1123-asm",
5872
fn: func(b *testing.B, key [4]byte, p []byte) {
5973
key32 := binary.LittleEndian.Uint32(key[:])
6074
b.ResetTimer()
@@ -64,6 +78,7 @@ func Benchmark_mask(b *testing.B) {
6478
}
6579
},
6680
},
81+
6782
{
6883
name: "gorilla",
6984
fn: func(b *testing.B, key [4]byte, p []byte) {

0 commit comments

Comments
 (0)