-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from goccy/feature/improve-performance
Improve performance ( Phase 1 )
- Loading branch information
Showing
4 changed files
with
173 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package yaml_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/goccy/go-yaml" | ||
goyaml2 "gopkg.in/yaml.v2" | ||
goyaml3 "gopkg.in/yaml.v3" | ||
) | ||
|
||
func Benchmark(b *testing.B) { | ||
const src = `--- | ||
id: 1 | ||
message: Hello, World | ||
verified: true | ||
elements: | ||
- one | ||
- 0.02 | ||
- null | ||
- -inf | ||
` | ||
type T struct { | ||
ID int `yaml:"id"` | ||
Message string `yaml:"message"` | ||
Verified bool `yaml:"verified,omitempty"` | ||
} | ||
|
||
b.Run("gopkg.in/yaml.v2", func(b *testing.B) { | ||
var t T | ||
for i := 0; i < b.N; i++ { | ||
if err := goyaml2.Unmarshal([]byte(src), &t); err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
}) | ||
b.Run("gopkg.in/yaml.v3", func(b *testing.B) { | ||
var t T | ||
for i := 0; i < b.N; i++ { | ||
if err := goyaml3.Unmarshal([]byte(src), &t); err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
}) | ||
b.Run("github.com/goccy/go-yaml", func(b *testing.B) { | ||
var t T | ||
for i := 0; i < b.N; i++ { | ||
if err := yaml.Unmarshal([]byte(src), &t); err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.