aboutsummaryrefslogtreecommitdiffhomepage
path: root/parser/frontmatter_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2018-02-12 17:31:37 +0100
committerBjørn Erik Pedersen <[email protected]>2018-02-12 18:16:48 +0100
commit51213e0be19fc19dbca9815afa95c73bd6d159c2 (patch)
treed8700baf405c676266e2d2bc215fe878944c81c2 /parser/frontmatter_test.go
parent1fa2417777d82b81bf37919ad02de4f5dcbf0d50 (diff)
downloadhugo-51213e0be19fc19dbca9815afa95c73bd6d159c2.tar.gz
hugo-51213e0be19fc19dbca9815afa95c73bd6d159c2.zip
parser: Add benchmarks for stringifyYAMLMapKeys
```bash BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps-4 500000 3269 ns/op 1080 B/op 16 allocs/op BenchmarkStringifyMapKeysStringsOnlyStringMaps-4 300000000 4.79 ns/op 0 B/op 0 allocs/op BenchmarkStringifyMapKeysIntegers-4 500000 2707 ns/op 1080 B/op 16 allocs/op ```
Diffstat (limited to 'parser/frontmatter_test.go')
-rw-r--r--parser/frontmatter_test.go69
1 files changed, 68 insertions, 1 deletions
diff --git a/parser/frontmatter_test.go b/parser/frontmatter_test.go
index a7a35fa07..9ac974951 100644
--- a/parser/frontmatter_test.go
+++ b/parser/frontmatter_test.go
@@ -323,7 +323,7 @@ func TestRemoveTOMLIdentifier(t *testing.T) {
func TestStringifyYAMLMapKeys(t *testing.T) {
cases := []struct {
- input map[interface{}]interface{}
+ input interface{}
want map[string]interface{}
}{
{
@@ -346,6 +346,10 @@ func TestStringifyYAMLMapKeys(t *testing.T) {
map[interface{}]interface{}{"a": map[interface{}]interface{}{"b": 1}},
map[string]interface{}{"a": map[string]interface{}{"b": 1}},
},
+ {
+ map[string]interface{}{"a": map[string]interface{}{"b": 1}},
+ map[string]interface{}{"a": map[string]interface{}{"b": 1}},
+ },
}
for i, c := range cases {
@@ -365,6 +369,69 @@ func BenchmarkFrontmatterTags(b *testing.B) {
}
}
+func BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps(b *testing.B) {
+ maps := make([]map[interface{}]interface{}, b.N)
+ for i := 0; i < b.N; i++ {
+ maps[i] = map[interface{}]interface{}{
+ "a": map[interface{}]interface{}{
+ "b": 32,
+ "c": 43,
+ "d": map[interface{}]interface{}{
+ "b": 32,
+ "c": 43,
+ },
+ },
+ "b": []interface{}{"a", "b"},
+ "c": "d",
+ }
+ }
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ stringifyYAMLMapKeys(maps[i])
+ }
+}
+
+func BenchmarkStringifyMapKeysStringsOnlyStringMaps(b *testing.B) {
+ m := map[string]interface{}{
+ "a": map[string]interface{}{
+ "b": 32,
+ "c": 43,
+ "d": map[string]interface{}{
+ "b": 32,
+ "c": 43,
+ },
+ },
+ "b": []interface{}{"a", "b"},
+ "c": "d",
+ }
+
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ stringifyYAMLMapKeys(m)
+ }
+}
+
+func BenchmarkStringifyMapKeysIntegers(b *testing.B) {
+ maps := make([]map[interface{}]interface{}, b.N)
+ for i := 0; i < b.N; i++ {
+ maps[i] = map[interface{}]interface{}{
+ 1: map[interface{}]interface{}{
+ 4: 32,
+ 5: 43,
+ 6: map[interface{}]interface{}{
+ 7: 32,
+ 8: 43,
+ },
+ },
+ 2: []interface{}{"a", "b"},
+ 3: "d",
+ }
+ }
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ stringifyYAMLMapKeys(maps[i])
+ }
+}
func doBenchmarkFrontmatter(b *testing.B, fileformat string, numTags int) {
yamlTemplate := `---
name: "Tags"