perf

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package perf captures performance metrics

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	Time    time.Duration
	Bytes   int64
	Objects int64
}

Diff represents the difference between two points in time

Example
package main

import (
	"fmt"
	"time"

	"github.com/FAU-CDI/drincw/pkg/perf"
)

func main() {
	// Diff holds both the amount of time an operation took,
	// the number of bytes consumed, and the total number of allocated objects.
	diff := perf.Diff{
		Time:    15 * time.Second,
		Bytes:   100,
		Objects: 100,
	}
	fmt.Println(diff)
}
Output:

15s, 100 B, 100 objects

func Since

func Since(start Snapshot) Diff

Since computes the diff between now, and the previous point in time

func (Diff) SetBytes

func (diff Diff) SetBytes(bytes int64) Diff

func (Diff) String

func (diff Diff) String() string

type Snapshot

type Snapshot struct {
	Time    time.Time
	Bytes   int64
	Objects int64
}

Snapshot represents metrics at a specific point in time

func Now

func Now() (s Snapshot)

Now returns a snapshot for the current moment

Example

An example of capturing performance metrics

package main

import (
	"fmt"
	"runtime"
	"time"

	"github.com/FAU-CDI/drincw/pkg/perf"
)

func main() {
	metrics := perf.Now()

	// some fancy and slow task
	{
		var stuff [10000]int
		defer runtime.KeepAlive(stuff)
		time.Sleep(1 * time.Second)
	}

	// print out performance metrics
	fmt.Println(perf.Since(metrics))
}

func (Snapshot) String

func (snapshot Snapshot) String() string

func (Snapshot) Sub

func (s Snapshot) Sub(other Snapshot) Diff

Sub subtracts the metrics for a difference snapshots

Jump to

Keyboard shortcuts

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