bench

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package bench measures the performance of dtx Null* wrappers against the idiomatic Go alternative — using pointers (*T) for nullable struct fields. Each domain entity appears in two variants (one dtx-typed, one pointer-typed) and every benchmark runs over three input profiles (all-valid, all-null, mixed) so the comparison reflects realistic fill ratios rather than a single shape.

The pointer variant uses the conventions a Go developer would actually reach for in production: omitempty on every nullable field and time.Time for date/datetime fields. As a consequence the JSON shapes are not byte-identical between the two variants — pointer JSON omits absent fields, dtx JSON emits them as explicit "null", and time.Time always serialises as RFC 3339 rather than the date-only layout dtx uses for NullDate. The TestClientJSONSizes helper reports the resulting byte sizes so the benchmark numbers can be read in context.

Run with:

go test ./bench/... -bench=. -benchmem

To filter to a single variant, profile, or operation, pass a more specific -bench expression:

go test ./bench/... -bench=Client/Null/Unmarshal/Mixed -benchmem

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientNull

type ClientNull struct {
	Id        int32            `json:"id"`
	FirstName types.NullString `json:"firstName,omitzero"`
	LastName  types.NullString `json:"lastName,omitzero"`
	Source    *LeadSource      `json:"source,omitempty"`
	Document  *DocumentNull    `json:"document,omitempty"`
	BirthDate types.NullDate   `json:"birthDate,omitzero"`
}

ClientNull is the dtx variant of Client.

func NewClientNull

func NewClientNull(p Profile) ClientNull

NewClientNull builds a ClientNull instance for the given profile.

type ClientPtr

type ClientPtr struct {
	Id        int32        `json:"id"`
	FirstName *string      `json:"firstName,omitempty"`
	LastName  *string      `json:"lastName,omitempty"`
	Source    *LeadSource  `json:"source,omitempty"`
	Document  *DocumentPtr `json:"document,omitempty"`
	BirthDate *time.Time   `json:"birthDate,omitempty"`
}

ClientPtr is the pointer variant of Client.

func NewClientPtr

func NewClientPtr(p Profile) ClientPtr

NewClientPtr builds a ClientPtr instance for the given profile.

type DocumentNull

type DocumentNull struct {
	TypeId     int16            `json:"typeId"`
	Number     types.NullString `json:"number,omitzero"`
	DateIssue  types.NullDate   `json:"dateIssue,omitzero"`
	DateExpiry types.NullDate   `json:"dateExpiry,omitzero"`
}

DocumentNull is the dtx variant of Document.

type DocumentPtr

type DocumentPtr struct {
	TypeId     int16      `json:"typeId"`
	Number     *string    `json:"number,omitempty"`
	DateIssue  *time.Time `json:"dateIssue,omitempty"`
	DateExpiry *time.Time `json:"dateExpiry,omitempty"`
}

DocumentPtr is the pointer variant of Document.

type LeadSource

type LeadSource struct {
	Id   int16  `json:"id"`
	Code string `json:"code"`
	Name string `json:"name"`
}

LeadSource is shared by both variants — every field is non-null, so there is no representation difference between the dtx and pointer styles for this entity.

type Profile

type Profile int

Profile describes how heavily nullable fields are populated in a generated instance.

const (
	// ProfileAllValid populates every nullable field with a value.
	ProfileAllValid Profile = iota
	// ProfileAllNull leaves every nullable field empty / nil.
	ProfileAllNull
	// ProfileMixed populates roughly half of the nullable fields, to
	// approximate a realistic record where some optional information
	// is present and some is missing.
	ProfileMixed
)

func (Profile) String

func (p Profile) String() string

String returns the human-readable profile name used in benchmark sub-test labels.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL