fastime

package module
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: MIT Imports: 7 Imported by: 45

README

release CircleCI codecov Codacy Badge Go Report Card GoDoc fastime is a super fast time function library for Go with zero memory allocation. fastime returns the approximate time.

Requirement

Go 1.16

Installation

go get github.com/kpango/fastime

Example

    now := fastime.Now().StartTimerD(context.Background(), time.Millisecond*5)
    defer fastime.Stop()

    // Create Instance
    ft := fastime.New().StartTimerD(context.Background(), time.Millisecond*5)
    defer ft.Stop()
    ft.Now()

Benchmark

go test -count=10 -run=NONE -bench . -benchmem
goos: linux
goarch: amd64
pkg: github.com/kpango/fastime
BenchmarkFastime-8   	2000000000	         0.45 ns/op	       0 B/op	       0 allocs/op
BenchmarkFastime-8   	2000000000	         0.45 ns/op	       0 B/op	       0 allocs/op
BenchmarkFastime-8   	2000000000	         0.45 ns/op	       0 B/op	       0 allocs/op
BenchmarkFastime-8   	2000000000	         0.45 ns/op	       0 B/op	       0 allocs/op
BenchmarkFastime-8   	2000000000	         0.45 ns/op	       0 B/op	       0 allocs/op
BenchmarkFastime-8   	2000000000	         0.45 ns/op	       0 B/op	       0 allocs/op
BenchmarkFastime-8   	2000000000	         0.45 ns/op	       0 B/op	       0 allocs/op
BenchmarkFastime-8   	2000000000	         0.45 ns/op	       0 B/op	       0 allocs/op
BenchmarkFastime-8   	2000000000	         0.45 ns/op	       0 B/op	       0 allocs/op
BenchmarkFastime-8   	2000000000	         0.46 ns/op	       0 B/op	       0 allocs/op
BenchmarkTime-8      	 1000000	      1683 ns/op	       0 B/op	       0 allocs/op
BenchmarkTime-8      	 1000000	      1720 ns/op	       0 B/op	       0 allocs/op
BenchmarkTime-8      	 1000000	      1688 ns/op	       0 B/op	       0 allocs/op
BenchmarkTime-8      	 1000000	      1716 ns/op	       0 B/op	       0 allocs/op
BenchmarkTime-8      	 1000000	      1691 ns/op	       0 B/op	       0 allocs/op
BenchmarkTime-8      	 1000000	      1693 ns/op	       0 B/op	       0 allocs/op
BenchmarkTime-8      	 1000000	      1703 ns/op	       0 B/op	       0 allocs/op
BenchmarkTime-8      	 1000000	      1668 ns/op	       0 B/op	       0 allocs/op
BenchmarkTime-8      	 1000000	      1685 ns/op	       0 B/op	       0 allocs/op
BenchmarkTime-8      	 1000000	      1716 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/kpango/fastime	26.873s

Contribution

  1. Fork it ( https://github.com/kpango/fastime/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

kpango

LICENSE

fastime released under MIT license, refer LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormattedNow added in v1.0.4

func FormattedNow() (now []byte)

FormattedNow returns formatted byte time

func GetFormat added in v1.1.0

func GetFormat() (form string)

func GetLocation added in v1.1.0

func GetLocation() (loc *time.Location)

func IsDaemonRunning added in v1.1.0

func IsDaemonRunning() (running bool)

func Now

func Now() (now time.Time)

Now returns current time

func Since added in v1.1.7

func Since(t time.Time) (dur time.Duration)

Since returns the time elapsed since t. It is shorthand for fastime.Now().Sub(t).

func Stop

func Stop()

Stop stops stopping time refresh daemon

func UnixNanoNow added in v1.0.1

func UnixNanoNow() (now int64)

UnixNanoNow returns current unix nano time

func UnixNow added in v1.0.3

func UnixNow() (now int64)

UnixNow returns current unix time

func UnixUNanoNow added in v1.0.2

func UnixUNanoNow() (now uint32)

UnixUNanoNow returns current unix nano time

func UnixUNow added in v1.0.3

func UnixUNow() (now uint32)

UnixUNow returns current unix time

Types

type Fastime

type Fastime interface {
	IsDaemonRunning() bool
	GetFormat() string
	SetFormat(format string) Fastime
	GetLocation() *time.Location
	SetLocation(location *time.Location) Fastime
	Now() time.Time
	Stop()
	UnixNow() int64
	UnixUNow() uint32
	UnixNanoNow() int64
	UnixUNanoNow() uint32
	FormattedNow() []byte
	Since(t time.Time) time.Duration
	StartTimerD(ctx context.Context, dur time.Duration) Fastime
}

func New

func New() (f Fastime)

New returns Fastime

func SetFormat added in v1.0.9

func SetFormat(format string) (ft Fastime)

SetFormat replaces time format

func SetLocation added in v1.1.0

func SetLocation(location *time.Location) (ft Fastime)

SetLocation replaces time location

func StartTimerD

func StartTimerD(ctx context.Context, dur time.Duration) (ft Fastime)

StartTimerD provides time refresh daemon

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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