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

Function BenchmarkMemoryWriter_Capacity

internal/caches/writer_memory_test.go:57–99  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

55}
56
57func BenchmarkMemoryWriter_Capacity(b *testing.B) {
58 b.ReportAllocs()
59
60 var storage = caches.NewMemoryStorage(&serverconfigs.HTTPCachePolicy{
61 Id: 0,
62 IsOn: false,
63 Name: "",
64 Description: "",
65 Capacity: &shared.SizeCapacity{
66 Count: 8,
67 Unit: shared.SizeCapacityUnitGB,
68 },
69 }, nil)
70 initErr := storage.Init()
71 if initErr != nil {
72 b.Fatal(initErr)
73 }
74
75 const size = 1 << 20
76 const chunkSize = 16 << 10
77 var data = bytes.Repeat([]byte{'A'}, chunkSize)
78
79 b.ResetTimer()
80
81 b.RunParallel(func(pb *testing.PB) {
82 for pb.Next() {
83 var writer = caches.NewMemoryWriter(storage, "a"+strconv.Itoa(rand.Int()), time.Now().Unix()+3600, 200, false, size, 1<<30, func(valueItem *caches.MemoryItem) {
84 })
85
86 for i := 0; i < size/chunkSize; i++ {
87 _, err := writer.Write(data)
88 if err != nil {
89 b.Fatal(err)
90 }
91 }
92
93 err := writer.Close()
94 if err != nil {
95 b.Fatal(err)
96 }
97 }
98 })
99}
100
101func BenchmarkMemoryWriter_Capacity_Disabled(b *testing.B) {
102 b.ReportAllocs()

Callers

nothing calls this directly

Calls 7

NewMemoryStorageFunction · 0.92
NewMemoryWriterFunction · 0.92
NextMethod · 0.80
UnixMethod · 0.80
InitMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected