MCPcopy Create free account
hub / github.com/cockroachdb/apd / TestSize

Function TestSize

decimal_test.go:872–926  ·  view source on GitHub ↗

TestSize tests the Size method on BigInt and Decimal. Unlike Sizeof, which returns the shallow size of the structs, the Size method reports the total memory footprint of each struct and all referenced objects.

(t *testing.T)

Source from the content-addressed store, hash-verified

870// returns the shallow size of the structs, the Size method reports the total
871// memory footprint of each struct and all referenced objects.
872func TestSize(t *testing.T) {
873 // map[uint_size][is_inline][type]size
874 exp := map[int]map[bool]map[string]uintptr{
875 32: {
876 true: {
877 "BigInt": 20,
878 "Decimal": 28,
879 },
880 false: {
881 "BigInt": 72,
882 "Decimal": 80,
883 },
884 },
885 64: {
886 true: {
887 "BigInt": 24,
888 "Decimal": 32,
889 },
890 false: {
891 "BigInt": 112,
892 "Decimal": 120,
893 },
894 },
895 }[bits.UintSize]
896
897 var d Decimal
898 if e, s := exp[true]["Decimal"], d.Size(); e != s {
899 t.Errorf("(*Decimal).Size() != %d: %d", e, s)
900 }
901 if e, s := exp[true]["BigInt"], d.Coeff.Size(); e != s {
902 t.Errorf("(*BigInt).Size() != %d: %d", e, s)
903 }
904 // Set to an inlinable value.
905 d.SetInt64(1234)
906 if e, s := exp[true]["Decimal"], d.Size(); e != s {
907 t.Errorf("(*Decimal).Size() != %d: %d", e, s)
908 }
909 if e, s := exp[true]["BigInt"], d.Coeff.Size(); e != s {
910 t.Errorf("(*BigInt).Size() != %d: %d", e, s)
911 }
912 // Set to a non-inlinable value.
913 if _, _, err := d.SetString("123456789123456789123456789.123456789123456789"); err != nil {
914 t.Fatal(err)
915 }
916 if d.Coeff.isInline() {
917 // Sanity-check, in case inlineWords changes.
918 t.Fatal("BigInt inlined large value. Did inlineWords change?")
919 }
920 if e, s := exp[false]["Decimal"], d.Size(); e != s {
921 t.Errorf("(*Decimal).Size() != %d: %d", e, s)
922 }
923 if e, s := exp[false]["BigInt"], d.Coeff.Size(); e != s {
924 t.Errorf("(*BigInt).Size() != %d: %d", e, s)
925 }
926}
927
928func TestJSONEncoding(t *testing.T) {
929 var encodingTests = []string{

Callers

nothing calls this directly

Calls 5

SizeMethod · 0.95
SetInt64Method · 0.95
SetStringMethod · 0.95
isInlineMethod · 0.80
SizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…