Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/musobarlab/go-bencmarktest-json
Benchmark JSON CamelCase vs SnakeCase
https://github.com/musobarlab/go-bencmarktest-json
Last synced: 8 days ago
JSON representation
Benchmark JSON CamelCase vs SnakeCase
- Host: GitHub
- URL: https://github.com/musobarlab/go-bencmarktest-json
- Owner: musobarlab
- Created: 2022-06-25T10:35:17.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-06-26T06:34:41.000Z (over 2 years ago)
- Last Synced: 2024-11-09T04:32:06.436Z (2 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Benchmark JSON CamelCase vs SnakeCase
### Run Benchmark Test
```shell
$ make test_bench
```### Result From My Machine
```
goos: darwin
goarch: amd64
cpu: Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz
```Result
```
go test . -bench=.
goos: darwin
goarch: amd64
pkg: github.com/musobarlab/go-bencmarktest-json
cpu: Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz
BenchmarkSerializeDataCamelToJSON-4 1848588 610.9 ns/op
BenchmarkSerializeDataSnakeToJSON-4 1821445 657.6 ns/op
BenchmarkDeserializeDataCamelFromJSON-4 449808 2612 ns/op
BenchmarkDeserializeDataSnakeFromJSON-4 444752 2684 ns/op
PASS
ok github.com/musobarlab/go-bencmarktest-json 7.516s
```JSON with `camelCase` is faster than `snakeCase` in encode and decode process.
```
Test Name Operation (Higher better) NS per Operation (Lower better)BenchmarkSerializeDataCamelToJSON-4 1848588 610.9 ns/op
BenchmarkSerializeDataSnakeToJSON-4 1821445 657.6 ns/op
BenchmarkDeserializeDataCamelFromJSON-4 449808 2612 ns/op
BenchmarkDeserializeDataSnakeFromJSON-4 444752 2684 ns/op
```#
In this example, the data is structured and uses the same data type, only the json field is differentStructure with CamelCase
```go
// DataCamel type
type DataCamel struct {
ID string `json:"id"`
NameNameNome string `json:"nameNameNome"`
BlaBleBloQuantity uint64 `json:"blaBleBloQuantity"`
Images []string `json:"images"`
}
```Structure with Snake_Case
```go
// DataSnake type
type DataSnake struct {
ID string `json:"id"`
NameNameNome string `json:"name_name_nome"`
BlaBleBloQuantity uint64 `json:"bla_ble_blo_quantity"`
Images []string `json:"images"`
}
```