gspeed

package
v0.0.0-...-f3abbe6 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 7 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Speed

type Speed float64

bit size of speed 为什么用float64而不用uint64?float64的表示范围比uint64大很多,unint64根本达不到YB级别

const (
	Kb Speed = 1 << (10 * iota) // 1 Kb = 1024 bits
	Mb                          // 1 Mb = 1048576 bits
	Gb
	Tb
	Pb
	Eb
	Zb
	Yb
)

Map between speed unit of bit and bits size

const (
	KB Speed = 8 * (1 << (10 * iota)) // 1 KB = (8 * 1024) bits
	MB                                // 1 MB = (8 * 1048576) bits
	GB
	TB
	PB
	EB
	ZB
	YB
)

Map between speed unit of byte and bits size

func FromBits

func FromBits(size float64) (Speed, error)

func FromBitsInterval

func FromBitsInterval(bits float64, interval time.Duration) (Speed, error)

func FromBytes

func FromBytes(size float64) (Speed, error)

func FromBytesInterval

func FromBytesInterval(bytes float64, interval time.Duration) (Speed, error)

func ParseString

func ParseString(speed string) (Speed, error)

speed string sample: "2M" "2Mb" "2Mbit" "2Mbits" "2Mbyte" "2Mbytes" "2 Mb" "*/s" "*ps"

func (Speed) BiggerThan

func (s Speed) BiggerThan(s2 Speed) bool

func (Speed) Equals

func (s Speed) Equals(s2 Speed) bool

func (Speed) GetBitSize

func (s Speed) GetBitSize() float64

func (Speed) GetByteSize

func (s Speed) GetByteSize() float64

func (Speed) MarshalJSON

func (s Speed) MarshalJSON() ([]byte, error)

func (Speed) SmallerThan

func (s Speed) SmallerThan(s2 Speed) bool

func (Speed) String

func (s Speed) String() string

func (*Speed) StringAuto

func (s *Speed) StringAuto() string

func (*Speed) StringWithBitUnit

func (s *Speed) StringWithBitUnit() string

func (*Speed) StringWithByteUnit

func (s *Speed) StringWithByteUnit() string

func (*Speed) UnmarshalJSON

func (s *Speed) UnmarshalJSON(b []byte) error

type SpeedCounter

type SpeedCounter struct {
	// contains filtered or unexported fields
}

func NewCounter

func NewCounter(dur time.Duration) *SpeedCounter

dur: 多长时间之内的数据作为参与统计速度的有效数据。此时长越长,计算得出的速度变化越均匀

func (*SpeedCounter) Add

func (c *SpeedCounter) Add(byteSize uint64)

func (*SpeedCounter) BeginCount

func (c *SpeedCounter) BeginCount()

这个接口什么时候调用?

func (*SpeedCounter) Get

func (c *SpeedCounter) Get() (*Speed, error)

func (*SpeedCounter) Reset

func (c *SpeedCounter) Reset()

Jump to

Keyboard shortcuts

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