Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fdfb53b

Browse files
committed
Added benchmarks for json deconding.
Results: $ go test -v -benchmem -bench BenchmarkIndexParsing github.com/arduino/arduino-cli/arduino/libraries/librariesindex === RUN TestIndexer --- PASS: TestIndexer (0.16s) goos: linux goarch: amd64 pkg: github.com/arduino/arduino-cli/arduino/libraries/librariesindex cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz BenchmarkIndexParsingStdJSON BenchmarkIndexParsingStdJSON-8 5 214872730 ns/op 94.52 MB/s 58956539 B/op 418973 allocs/op BenchmarkIndexParsingEasyJSON BenchmarkIndexParsingEasyJSON-8 16 69215472 ns/op 293.42 MB/s 56162664 B/op 418966 allocs/op PASS ok github.com/arduino/arduino-cli/arduino/libraries/librariesindex 4.442s easyjson is 3x faster.
1 parent 479f143 commit fdfb53b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎arduino/libraries/librariesindex/index_test.go‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
package librariesindex
1717

1818
import (
19+
json "encoding/json"
1920
"fmt"
2021
"testing"
2122

2223
"github.com/arduino/arduino-cli/arduino/libraries"
2324
"github.com/arduino/go-paths-helper"
25+
easyjson "github.com/mailru/easyjson"
2426
"github.com/stretchr/testify/require"
2527
semver "go.bug.st/relaxed-semver"
2628
)
@@ -113,3 +115,27 @@ func TestIndexer(t *testing.T) {
113115
require.Contains(t, resolve2, bear172)
114116
require.Contains(t, resolve2, http040)
115117
}
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /