|
16 | 16 | package librariesindex
|
17 | 17 |
|
18 | 18 | import (
|
| 19 | + json "encoding/json" |
19 | 20 | "fmt"
|
20 | 21 | "testing"
|
21 | 22 |
|
22 | 23 | "github.com/arduino/arduino-cli/arduino/libraries"
|
23 | 24 | "github.com/arduino/go-paths-helper"
|
| 25 | + easyjson "github.com/mailru/easyjson" |
24 | 26 | "github.com/stretchr/testify/require"
|
25 | 27 | semver "go.bug.st/relaxed-semver"
|
26 | 28 | )
|
@@ -113,3 +115,27 @@ func TestIndexer(t *testing.T) {
|
113 | 115 | require.Contains(t, resolve2, bear172)
|
114 | 116 | require.Contains(t, resolve2, http040)
|
115 | 117 | }
|
| 118 | + |
| 119 | +func BenchmarkIndexParsingStdJSON(b *testing.B) { |
| 120 | + indexFile := paths.New("testdata/library_index.json") |
| 121 | + buff, err := indexFile.ReadFile() |
| 122 | + require.NoError(b, err) |
| 123 | + b.SetBytes(int64(len(buff))) |
| 124 | + for i := 0; i < b.N; i++ { |
| 125 | + var i indexJSON |
| 126 | + err = json.Unmarshal(buff, &i) |
| 127 | + require.NoError(b, err) |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +func BenchmarkIndexParsingEasyJSON(b *testing.B) { |
| 132 | + indexFile := paths.New("testdata/library_index.json") |
| 133 | + buff, err := indexFile.ReadFile() |
| 134 | + require.NoError(b, err) |
| 135 | + b.SetBytes(int64(len(buff))) |
| 136 | + for i := 0; i < b.N; i++ { |
| 137 | + var i indexJSON |
| 138 | + err = easyjson.Unmarshal(buff, &i) |
| 139 | + require.NoError(b, err) |
| 140 | + } |
| 141 | +} |
0 commit comments