fperf

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: MIT Imports: 3 Imported by: 0

README

fperf

This is a module allowing to measure run time of functions and methods in Go.

How to Measure

There are 2 options to measure run time:

  • defer special helper function
func FuncToMeasure() {
    defer MeasureRunTime(reportRunTime)()
    // some code
}
  • embed measurement
func FuncToMeasure() {
    // some code
}

func main() {
    ef := EmbedRunTimeMeasurement(FuncToMeasure, reportRunTime).(func())
    ef()
}

Both options use a callback to report function's (method's) name and run duration:

type ReportCallback func(name string, duration time.Duration)

An example of the callback:

func reportRunTime(name string, duration time.Duration) {
    fmt.Fprintf(os.Stderr, "%q func took %v\n", name, duration)
}

Thus an app can decide how to print measurements.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmbedRunTimeMeasurement

func EmbedRunTimeMeasurement(f interface{}, report ReportCallback) interface{}

func MeasureRunTime

func MeasureRunTime(report ReportCallback) func()

Types

type ReportCallback

type ReportCallback func(name string, duration time.Duration)

Jump to

Keyboard shortcuts

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