Skip to content

Commit

Permalink
SignedBlindedBeaconBlock SSZ + benchmark ssz vs json
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Oct 6, 2022
1 parent 5b07588 commit 5b8e47b
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lint:

generate-ssz:
rm -f types/builder_encoding.go types/signing_encoding.go types/common_encoding.go
sszgen --path types --include ../go-ethereum/common/hexutil --objs Eth1Data,BeaconBlockHeader,SignedBeaconBlockHeader,ProposerSlashing,Checkpoint,AttestationData,IndexedAttestation,AttesterSlashing,Attestation,Deposit,VoluntaryExit,SyncAggregate,ExecutionPayloadHeader,VersionedExecutionPayloadHeader,BlindedBeaconBlockBody,BlindedBeaconBlock,RegisterValidatorRequestMessage,BuilderBid,SignedBuilderBid,SigningData,ForkData,Transactions,BidTraceMessage,BuilderSubmitBlockRequestMessage,BuilderSubmitBlockResponseMessage
sszgen --path types --include ../go-ethereum/common/hexutil --objs Eth1Data,BeaconBlockHeader,SignedBeaconBlockHeader,ProposerSlashing,Checkpoint,AttestationData,IndexedAttestation,AttesterSlashing,Attestation,Deposit,VoluntaryExit,SyncAggregate,ExecutionPayloadHeader,VersionedExecutionPayloadHeader,BlindedBeaconBlockBody,BlindedBeaconBlock,SignedBlindedBeaconBlock,RegisterValidatorRequestMessage,BuilderBid,SignedBuilderBid,SigningData,ForkData,Transactions,BidTraceMessage,BuilderSubmitBlockRequestMessage,BuilderSubmitBlockResponseMessage

cover:
go test -coverprofile=/tmp/go-sim-lb.cover.tmp ./...
Expand Down
105 changes: 104 additions & 1 deletion types/builder_encoding.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions types/encoding_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package types

import (
"encoding/json"
"os"
"testing"

"github.com/stretchr/testify/require"
)

func BenchmarkJSONvsSSZEncoding(b *testing.B) {
var err error
jsonFile, err := os.Open("../testdata/signed-blinded-beacon-block-with-deposit.json")
require.NoError(b, err)
defer jsonFile.Close()
signedBlindedBeaconBlock := new(SignedBlindedBeaconBlock)
require.NoError(b, DecodeJSON(jsonFile, &signedBlindedBeaconBlock))
signedBlindedBeaconBlockJSONBytes, err := json.Marshal(signedBlindedBeaconBlock)
require.NoError(b, err)
signedBlindedBeaconBlockSSZBytes, err := signedBlindedBeaconBlock.MarshalSSZ()
require.NoError(b, err)

b.Run("Encode JSON", func(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err = json.Marshal(signedBlindedBeaconBlock)
require.NoError(b, err)
}
})

b.Run("Encode SSZ", func(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err = signedBlindedBeaconBlock.MarshalSSZ()
require.NoError(b, err)
}
})

b.Run("Decode JSON", func(b *testing.B) {
_blindedBeaconBlock := new(SignedBlindedBeaconBlock)
for n := 0; n < b.N; n++ {
err = json.Unmarshal(signedBlindedBeaconBlockJSONBytes, _blindedBeaconBlock)
require.NoError(b, err)
}
})

b.Run("Decode SSZ", func(b *testing.B) {
_blindedBeaconBlock := new(SignedBlindedBeaconBlock)
for n := 0; n < b.N; n++ {
err = _blindedBeaconBlock.UnmarshalSSZ(signedBlindedBeaconBlockSSZBytes)
require.NoError(b, err)
}
})
}

0 comments on commit 5b8e47b

Please sign in to comment.