MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / BenchmarkDocumentParsing

Function BenchmarkDocumentParsing

xmlparser/document_test.go:103–150  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

101}
102
103func BenchmarkDocumentParsing(b *testing.B) {
104 testImagesPath, err := filepath.Abs("../testdata/test-images/svg-test-suite")
105 if err != nil {
106 b.Fatal(err)
107 }
108
109 samples := [][]byte{}
110
111 err = filepath.Walk(testImagesPath, func(path string, info os.FileInfo, err error) error {
112 if err != nil {
113 b.Fatal(err)
114 }
115
116 // Skip directories
117 if info.IsDir() {
118 return nil
119 }
120
121 // Skip non-SVG files
122 if filepath.Ext(path) != ".svg" {
123 return nil
124 }
125
126 // Read SVG file
127 data, err := os.ReadFile(path)
128 if err != nil {
129 b.Fatal(err)
130 }
131
132 samples = append(samples, data)
133 return nil
134 })
135
136 if err != nil {
137 b.Fatal(err)
138 }
139
140 b.ResetTimer()
141
142 for b.Loop() {
143 for _, sample := range samples {
144 _, err := xmlparser.NewDocument(bytes.NewReader(sample))
145 if err != nil {
146 b.Fatal(err)
147 }
148 }
149 }
150}

Callers

nothing calls this directly

Calls 2

NewDocumentFunction · 0.92
ExtMethod · 0.80

Tested by

no test coverage detected