Skip to content

Commit adb0181

Browse files
json: more benchmarking
1 parent f8df28e commit adb0181

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

internal/magic/magic_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,16 @@ our final approach into Coruscant.
231231
Srt([]byte(subtitle), 0)
232232
}
233233
}
234+
235+
func BenchmarkJSON(b *testing.B) {
236+
var sample = []byte("{" +
237+
// It's no problem to repeat the same keys. The parser does not mind.
238+
strings.Repeat(`"fruit": {"apple": [{"red": 1}]}, "sizes": ["Large", 10, {"size": "small"}], "color": "Red",`, 1000) +
239+
`"fruit": "Apple", "size": "Large", "color": "Red"}`)
240+
b.ReportAllocs()
241+
for i := 0; i < b.N; i++ {
242+
if !JSON(sample, 0) {
243+
b.Error("should always be true")
244+
}
245+
}
246+
}

mimetype_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var testcases = []testcase{
9696
{"flac", "\x66\x4C\x61\x43\x00\x00\x00\x22", "audio/flac", true},
9797
{"flv", "\x46\x4C\x56\x01", "video/x-flv", true},
9898
{"gbr", offset(20, "GIMP"), "image/x-gimp-gbr", true},
99-
{"geojson", `{"type":"Feature"}`, "application/geo+json", false},
99+
{"geojson", `{"type":"Feature"}`, "application/geo+json", true},
100100
{"gif 87", "GIF87a", "image/gif", true},
101101
{"gif 89", "GIF89a", "image/gif", false},
102102
{"glb 1", "\x67\x6C\x54\x46\x02\x00\x00\x00", "model/gltf-binary", true},
@@ -142,7 +142,7 @@ var testcases = []testcase{
142142
{"json", `{"key":"val"}`, "application/json", true},
143143
{"json issue#239", "{\x0A\x09\x09\"key\":\"val\"}\x0A", "application/json", false},
144144
// json.{int,string}.txt contain a single JSON value. They are valid JSON
145-
// documentsthey should not be detected as application/json. This mimics
145+
// documents but they should not be detected as application/json. This mimics
146146
// the behaviour of the file utility and seems the correct thing to do.
147147
{"json.int.txt", "1", "text/plain; charset=utf-8", false},
148148
{"json.float.txt", "1.5", "text/plain; charset=utf-8", false},

0 commit comments

Comments
 (0)