size

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 4 Imported by: 4

Documentation

Overview

Package size provides value size operations.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Of

func Of(data interface{}) int

Of returns the size in byte a value(not type) costs.

Since 0.1.0

func Stat

func Stat(v interface{}, depth int, maxItem int, opts ...interface{}) string

Stat returns a multi line string describe size of every component of a vavlue, such as slice element, struct member:

   size_test.my: 48
	   a: []int32: 36
		   0: int32: 4
		   1: int32: 4
		   2: int32: 4
	   b: [3]int32: 12
		   0: int32: 4
		   1: int32: 4
		   2: int32: 4

Since 0.1.0

Example
package main

import (
	"fmt"
	"github.com/openacid/low/size"
)

func main() {
	type my struct {
		a []int32
		b [3]int32
	}

	v := my{
		a: []int32{1, 2, 3},
		b: [3]int32{4, 5, 6},
	}

	fmt.Println(size.Of(v))
	got := size.Stat(v, 10, 100)
	fmt.Println(got)

}
Output:

48
size_test.my: 48
    a: []int32: 36
        0: int32: 4
        1: int32: 4
        2: int32: 4
    b: [3]int32: 12
        0: int32: 4
        1: int32: 4
        2: int32: 4

Types

type Opt added in v0.1.11

type Opt struct {

	// AvgOf being a non-zero value indicates to display average.
	//
	// Since 0.1.11
	AvgOf int

	// AvgUnit specifies the unit of size to use.
	// By default it is byte.
	// Set AvgUnit to 1.0/8 to display size in bit.
	//
	// Since 0.1.11
	AvgUnit float64
}

Opt defines options for size.Stat()

Since 0.1.11

Jump to

Keyboard shortcuts

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