Skip to content

Commit

Permalink
Added benchmarks for json deconding.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cmaglie committed May 4, 2022
1 parent 479f143 commit fdfb53b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions arduino/libraries/librariesindex/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package librariesindex

import (
json "encoding/json"
"fmt"
"testing"

"github.com/arduino/arduino-cli/arduino/libraries"
"github.com/arduino/go-paths-helper"
easyjson "github.com/mailru/easyjson"
"github.com/stretchr/testify/require"
semver "go.bug.st/relaxed-semver"
)
Expand Down Expand Up @@ -113,3 +115,27 @@ func TestIndexer(t *testing.T) {
require.Contains(t, resolve2, bear172)
require.Contains(t, resolve2, http040)
}

func BenchmarkIndexParsingStdJSON(b *testing.B) {
indexFile := paths.New("testdata/library_index.json")
buff, err := indexFile.ReadFile()
require.NoError(b, err)
b.SetBytes(int64(len(buff)))
for i := 0; i < b.N; i++ {
var i indexJSON
err = json.Unmarshal(buff, &i)
require.NoError(b, err)
}
}

func BenchmarkIndexParsingEasyJSON(b *testing.B) {
indexFile := paths.New("testdata/library_index.json")
buff, err := indexFile.ReadFile()
require.NoError(b, err)
b.SetBytes(int64(len(buff)))
for i := 0; i < b.N; i++ {
var i indexJSON
err = easyjson.Unmarshal(buff, &i)
require.NoError(b, err)
}
}

0 comments on commit fdfb53b

Please sign in to comment.