mono

package
v0.0.0-...-113f59a Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package mono provides fast monotonic time. On most platforms, mono.Now is about 2x faster than time.Now. However, time.Now is really fast, and nicer to use.

For almost all purposes, you should use time.Now.

Package mono exists because we get the current time multiple times per network packet, at which point it makes a measurable difference.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Since

func Since(t Time) time.Duration

Since returns the time elapsed since t.

Types

type Time

type Time int64

Time is the number of nanoseconds elapsed since an unspecified reference start time.

func Now

func Now() Time

Now returns the current monotonic time.

func (Time) Add

func (t Time) Add(d time.Duration) Time

Add returns t+d.

func (Time) After

func (t Time) After(n Time) bool

After reports t > n, whether t is after n.

func (Time) Before

func (t Time) Before(n Time) bool

Before reports t < n, whether t is before n.

func (Time) IsZero

func (t Time) IsZero() bool

IsZero reports whether t == 0.

func (*Time) LoadAtomic

func (t *Time) LoadAtomic() Time

LoadAtomic does an atomic load *t.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON formats t for JSON as if it were a time.Time. We format Time this way for backwards-compatibility. Time does not survive a MarshalJSON/UnmarshalJSON round trip unchanged across different invocations of the Go process. This is best-effort only. Since t is a monotonic time, it can vary from the actual wall clock by arbitrary amounts. Even in the best of circumstances, it may vary by a few milliseconds.

func (*Time) StoreAtomic

func (t *Time) StoreAtomic(new Time)

StoreAtomic does an atomic store *t = new.

func (Time) String

func (t Time) String() string

String prints t, including an estimated equivalent wall clock. This is best-effort only, for rough debugging purposes only. Since t is a monotonic time, it can vary from the actual wall clock by arbitrary amounts. Even in the best of circumstances, it may vary by a few milliseconds.

func (Time) Sub

func (t Time) Sub(n Time) time.Duration

Sub returns t-n, the duration from n to t.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON sets t according to data. Time does not survive a MarshalJSON/UnmarshalJSON round trip unchanged across different invocations of the Go process. This is best-effort only.

func (Time) WallTime

func (t Time) WallTime() time.Time

WallTime returns an approximate wall time that corresponded to t.

Jump to

Keyboard shortcuts

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