Sample project to compare Protocol Buffer versus JSON.
To run the project you need to install the GNU Make, protobuffer compiler and go code generator.
- Protobuffer compiler
- Go code generator
go install google.golang.org/protobuf/cmd/protoc-gen-go
- GNU Make
- The way to install will depend on your system environment
- Docker
- Docker Compose
- Redis Client
- You can install any Redis Client for your system to login and show all saved values
-
make help
- Show all make commands
-
make compile-protoc-win
- For that, you need to have
$PROTOC
name as an environment variable to protoc - Generates go code from proto file to Windows
- For that, you need to have
-
make compile-protoc-macos
- Generates go code from proto file to MacOS
-
make run-proto
- Run Protocol Buffer project and insert data on cache
-
make run-json
- Run JSON project and insert data on cache
-
make docker-build-up
- Build and start all containers
-
make docker-up
- Start all containers
-
make docker-down
- Stop all containers
-
make docker-ps
- Show all containers running
-
make proto-bench
- Run all benchmark tests to protocol buffer format
-
make json-bench
- Run all benchmark tests to json format
Presenting the results of running benchmark tests to compare Marshal and Unmarshal using Protocol Buffer and JSON, as well as Redis memory usage with 10,000 inserted items
Tips:
- Each test ran for 10 seconds
- The first column is the number of iterations run, this is a fairly light process, so it completes quickly, and many iterations can be run
ns/op
column - this is the average time each function call takes to complete
# Redis
used_memory: 2965888
Marshal: ≅26% more performative
Unmarshal: ≅85% more performative
# Redis (≅25% less memory used)
used_memory: 2225616