defract

package
v0.0.0-...-1c30942 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: ISC Imports: 7 Imported by: 0

README

Benchmarks

IsZero

graph

Name Iterations Time per Op Throughput
BenchmarkIsZeroStreq/byte-8 171917054 6.613 ns/op 1209.68 MB/s
BenchmarkIsZeroStreq/dbyte-8 156105722 7.422 ns/op 2155.62 MB/s
BenchmarkIsZeroStreq/big-8 16297855 65.91 ns/op 31072.66 MB/s
BenchmarkIsZeroStreq/massive-8 69648 15566 ns/op 33682.58 MB/s
BenchmarkIsZeroStreq/gigantic-8 454539020 2.617 ns/op 1602525636.73 MB/s
BenchmarkIsZeroStreq/byte_parallel-8 829908123 1.410 ns/op 5673.39 MB/s
BenchmarkIsZeroStreq/dbyte_parallel-8 696951979 1.583 ns/op 10105.05 MB/s
BenchmarkIsZeroStreq/big_parallel-8 53131268 20.36 ns/op 100584.94 MB/s
BenchmarkIsZeroStreq/massive_parallel-8 213414 5011 ns/op 104623.58 MB/s
BenchmarkIsZeroStreq/gigantic_parallel-8 1000000000 0.8339 ns/op 5029684228.34 MB/s
BenchmarkIsZero8Bytes/byte-8 327868894 3.433 ns/op 2329.99 MB/s
BenchmarkIsZero8Bytes/dbyte-8 313772871 3.931 ns/op 4069.99 MB/s
BenchmarkIsZero8Bytes/big-8 5515704 201.2 ns/op 10179.95 MB/s
BenchmarkIsZero8Bytes/massive-8 24033 47869 ns/op 10952.55 MB/s
BenchmarkIsZero8Bytes/gigantic-8 2608 467295 ns/op 8975.71 MB/s
BenchmarkIsZero8Bytes/byte_parallel-8 1000000000 1.060 ns/op 7547.98 MB/s
BenchmarkIsZero8Bytes/dbyte_parallel-8 932357254 1.238 ns/op 12926.06 MB/s
BenchmarkIsZero8Bytes/big_parallel-8 18687656 57.45 ns/op 35645.74 MB/s
BenchmarkIsZero8Bytes/massive_parallel-8 80784 14416 ns/op 36367.27 MB/s
BenchmarkIsZero8Bytes/gigantic_parallel-8 8664 119811 ns/op 35007.77 MB/s
BenchmarkIsZero16Bytes/byte-8 100000000 10.21 ns/op 783.30 MB/s
BenchmarkIsZero16Bytes/dbyte-8 262728376 4.515 ns/op 3544.14 MB/s
BenchmarkIsZero16Bytes/big-8 4765987 256.6 ns/op 7981.03 MB/s
BenchmarkIsZero16Bytes/massive-8 18633 62969 ns/op 8326.09 MB/s
BenchmarkIsZero16Bytes/gigantic-8 2210 543225 ns/op 7721.12 MB/s
BenchmarkIsZero16Bytes/byte_parallel-8 446812456 2.618 ns/op 3055.72 MB/s
BenchmarkIsZero16Bytes/dbyte_parallel-8 815567397 1.396 ns/op 11462.87 MB/s
BenchmarkIsZero16Bytes/big_parallel-8 16607584 69.63 ns/op 29414.54 MB/s
BenchmarkIsZero16Bytes/massive_parallel-8 66019 17365 ns/op 30191.68 MB/s
BenchmarkIsZero16Bytes/gigantic_parallel-8 7453 150101 ns/op 27943.21 MB/s

Documentation

Overview

Package defract is a reflect-like package that utilizes heavy caching with unsafe to improve its performance.

Index

Constants

This section is empty.

Variables

View Source
var ByteSlice = reflect.TypeOf([]byte(nil))

ByteSlice is the reflect.Type value for a byte slice.

View Source
var IsLittleEndian bool

IsLittleEndian is true if the current machine is a Little-Endian machine.

Functions

func AllocIndirect

func AllocIndirect(typ reflect.Type, ptr unsafe.Pointer) (reflect.Type, unsafe.Pointer)

AllocIndirect allocates a pointer type until the value is reached, and the pointer to that newly-allocated value is returned, along with the underlying type. If the given ptr is not nil, then the memory will be reused.

func AllocSlice

func AllocSlice(ptr unsafe.Pointer, size, len int64)

AllocSlice allocates a slice that is len*typsize bytes large. The returned pointer is the data pointer.

func BytesToStr

func BytesToStr(bytes []byte) string

BytesToStr converts the given bytes to string without copying.

func CopyString

func CopyString(dst unsafe.Pointer, src []byte)

CopyString tries to reduce allocations by reusing the backing array if there's enough length.

func GetStructSchema

func GetStructSchema(v interface{}) string

GetStructSchema gets the struct schema of the given struct value's type. If v isn't a struct, then it panics.

func Indirect

func Indirect(typ reflect.Type, ptr unsafe.Pointer) (reflect.Type, unsafe.Pointer)

Indirect dereferences the pointer until the type is no longer one. If any of the pointers are nil, then zero-values are returned.

func IndirectOnce

func IndirectOnce(ptr unsafe.Pointer) unsafe.Pointer

IndirectOnce dereferences ptr once. It returns nil if ptr is nil.

func IntLE

func IntLE(i *int) []byte

IntLE is a helper function that converts the given int value into bytes, ideally without copying on a 64-bit little-endian machine. The bytes are always in little-endian.

func InterfacePtr

func InterfacePtr(v interface{}) unsafe.Pointer

InterfacePtr returns the pointer to the internal value of the given interface.

func IsZero

func IsZero(ptr unsafe.Pointer, size uintptr) bool

IsZero returns true if the data at the given pointer is all zero. The function scans the data up to the given length.

func IsZeroBytes

func IsZeroBytes(bytes []byte) bool

IsZeroBytes is the bytes equivalent of the IsZero function.

func NumberLE

func NumberLE(kind reflect.Kind, ptr unsafe.Pointer) []byte

NumberLE returns the little-endian variant of the given number at the pointer. It does not handle variable-length integers, and is meant only for other statically sized integer or floating-point types.

If this method is called on a Big Endian macnine, then a new byte buffer will be allocated from the pool.

func ReadInt64LE

func ReadInt64LE(dst []byte) (int64, bool)

ReadInt64LE reads dst and returns an int64 if dst has enough data. Otherwise, false is returned.

func ReadNumberLE

func ReadNumberLE(b []byte, kind reflect.Kind, ptr unsafe.Pointer) bool

ReadNumberLE reads the little-endian number of the given byte slice into the pointer. If bound checking fails, false is returned.

func SliceInfo

func SliceInfo(ptr unsafe.Pointer) (unsafe.Pointer, int, int)

SliceInfo returns the backing array pointer and length of the slice at the given pointer.

func SliceSetLen

func SliceSetLen(ptr unsafe.Pointer, len int64) unsafe.Pointer

SliceSetLen sets the length of the slice at the given pointer and returns the pointer to the backing array.

func StrToBytes

func StrToBytes(str *string) []byte

StrToBytes converts the given string to bytes without copying.

func StringInfo

func StringInfo(ptr unsafe.Pointer) (unsafe.Pointer, int)

StringInfo returns the backing array pointer and length of the string at the given pointer. It also works with byte slices.

func UintLE

func UintLE(u *uint) []byte

UintLE is a helper function that converts the given uint64 value into bytes, ideally without copying on a 64-bit little-endian machine. The bytes are always in little-endian.

func UnderlyingPtr

func UnderlyingPtr(v interface{}) (reflect.Type, unsafe.Pointer)

UnderlyingPtr returns the type of and the pointer to the value of the interface by dereferencing it until the actual value is reached.

func WithinBytes

func WithinBytes(outer, inner []byte) bool

WithinBytes returns true if the inner slice is within outer slice.

func WriteInt64LE

func WriteInt64LE(dst []byte, i int64)

WriteInt64LE writes the given int64 into the given byte slice.

func ZeroOut

func ZeroOut(ptr unsafe.Pointer, size uintptr)

ZeroOut fills the given buffer with zeroes.

func ZeroOutBytes

func ZeroOutBytes(bytes []byte)

ZeroOutBytes fills the given bytes slice with zeroes.

Types

type SliceHeader

type SliceHeader struct {
	Data unsafe.Pointer
	Len  int
	Cap  int
}

SliceHeader is the header structure that contains an unsafe.Pointer data field instead of uintptr.

type StringHeader

type StringHeader struct {
	Data unsafe.Pointer
	Len  int
}

StringHeader is a safer reflect.StringHeader.

type StructField

type StructField struct {
	Type   reflect.Type
	Name   []byte
	Kind   reflect.Kind
	Size   uintptr
	Offset uintptr

	// Indirect is true if the type is pointer.
	Indirect bool
}

type StructInfo

type StructInfo struct {
	Type   reflect.Type
	Fields []StructField

	// RawSchema describes the schema of the struct. The description currently
	// includes field names, though this may change in the future.
	RawSchema []byte
}

func GetStructInfo

func GetStructInfo(typ reflect.Type) *StructInfo

GetStructInfo returns the struct type information for the given struct value. It assumes that typ is a type of a struct and does not do checks.

Jump to

Keyboard shortcuts

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