diff --git a/internal/binary/binary_bench_test.go b/internal/binary/binary_bench_test.go index d414ea1..5e9ed31 100644 --- a/internal/binary/binary_bench_test.go +++ b/internal/binary/binary_bench_test.go @@ -11,43 +11,6 @@ import ( "github.com/nbd-wtf/go-nostr/test_common" ) -func BenchmarkBinaryEncoding(b *testing.B) { - events := make([]*nostr.Event, len(test_common.NormalEvents)) - binaryEvents := make([]*Event, len(test_common.NormalEvents)) - for i, jevt := range test_common.NormalEvents { - evt := &nostr.Event{} - json.Unmarshal([]byte(jevt), evt) - events[i] = evt - binaryEvents[i] = BinaryEvent(evt) - } - - b.Run("easyjson.Marshal", func(b *testing.B) { - for i := 0; i < b.N; i++ { - for _, evt := range events { - easyjson.Marshal(evt) - } - } - }) - - b.Run("gob.Encode", func(b *testing.B) { - for i := 0; i < b.N; i++ { - for _, evt := range events { - var buf bytes.Buffer - gob.NewEncoder(&buf).Encode(evt) - _ = buf.Bytes() - } - } - }) - - b.Run("binary.Marshal", func(b *testing.B) { - for i := 0; i < b.N; i++ { - for _, evt := range events { - Marshal(evt) - } - } - }) -} - func BenchmarkBinaryDecoding(b *testing.B) { events := make([][]byte, len(test_common.NormalEvents)) gevents := make([][]byte, len(test_common.NormalEvents)) diff --git a/internal/binary/event.go b/internal/binary/event.go deleted file mode 100644 index 5aa0536..0000000 --- a/internal/binary/event.go +++ /dev/null @@ -1,44 +0,0 @@ -package binary - -import ( - "encoding/hex" - - "github.com/nbd-wtf/go-nostr" -) - -type Event struct { - PubKey [32]byte - Sig [64]byte - ID [32]byte - Kind uint16 - CreatedAt nostr.Timestamp - Content string - Tags nostr.Tags -} - -func BinaryEvent(evt *nostr.Event) *Event { - bevt := Event{ - Tags: evt.Tags, - Content: evt.Content, - Kind: uint16(evt.Kind), - CreatedAt: evt.CreatedAt, - } - - hex.Decode(bevt.ID[:], []byte(evt.ID)) - hex.Decode(bevt.PubKey[:], []byte(evt.PubKey)) - hex.Decode(bevt.Sig[:], []byte(evt.Sig)) - - return &bevt -} - -func (bevt *Event) ToNormalEvent() *nostr.Event { - return &nostr.Event{ - Tags: bevt.Tags, - Content: bevt.Content, - Kind: int(bevt.Kind), - CreatedAt: bevt.CreatedAt, - ID: hex.EncodeToString(bevt.ID[:]), - PubKey: hex.EncodeToString(bevt.PubKey[:]), - Sig: hex.EncodeToString(bevt.Sig[:]), - } -}