MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / TestUserAgentParser_Memory

Function TestUserAgentParser_Memory

internal/stats/user_agent_parser_test.go:31–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func TestUserAgentParser_Memory(t *testing.T) {
32 var stat1 = &runtime.MemStats{}
33 runtime.ReadMemStats(stat1)
34
35 var parser = stats.NewUserAgentParser()
36
37 for i := 0; i < 1_000_000; i++ {
38 parser.Parse("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36 Test/" + types.String(rands.Int(0, 1_000_000)))
39 }
40
41 runtime.GC()
42 debug.FreeOSMemory()
43
44 var stat2 = &runtime.MemStats{}
45 runtime.ReadMemStats(stat2)
46
47 t.Log("max cache items:", parser.MaxCacheItems())
48 t.Log("cache:", parser.Len(), "usage:", (stat2.HeapInuse-stat1.HeapInuse)>>20, "MB")
49}
50
51func TestNewUserAgentParser_GC(t *testing.T) {
52 if !testutils.IsSingleTesting() {

Callers

nothing calls this directly

Calls 7

NewUserAgentParserFunction · 0.92
ParseMethod · 0.80
LogMethod · 0.80
MaxCacheItemsMethod · 0.80
GCMethod · 0.65
StringMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected