MCPcopy Index your code
hub / github.com/coder/websocket / BenchmarkJSON

Function BenchmarkJSON

wsjson/wsjson_test.go:12–53  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

10)
11
12func BenchmarkJSON(b *testing.B) {
13 sizes := []int{
14 8,
15 16,
16 32,
17 128,
18 256,
19 512,
20 1024,
21 2048,
22 4096,
23 8192,
24 16384,
25 }
26
27 b.Run("json.Encoder", func(b *testing.B) {
28 for _, size := range sizes {
29 b.Run(strconv.Itoa(size), func(b *testing.B) {
30 msg := xrand.String(size)
31 b.SetBytes(int64(size))
32 b.ReportAllocs()
33 b.ResetTimer()
34 for i := 0; i < b.N; i++ {
35 json.NewEncoder(io.Discard).Encode(msg)
36 }
37 })
38 }
39 })
40 b.Run("json.Marshal", func(b *testing.B) {
41 for _, size := range sizes {
42 b.Run(strconv.Itoa(size), func(b *testing.B) {
43 msg := xrand.String(size)
44 b.SetBytes(int64(size))
45 b.ReportAllocs()
46 b.ResetTimer()
47 for i := 0; i < b.N; i++ {
48 json.Marshal(msg)
49 }
50 })
51 }
52 })
53}

Callers

nothing calls this directly

Calls 1

StringFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…