Thanks to visit codestin.com
Credit goes to github.com

Skip to content

barkhayot/tempo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tempo - A Simple Go Timer Package

tempo is a Go package for tracking and logging the execution time of processes. It supports optional configurations such as labels and thresholds to mark slow execution.

Installation

You can install the package using go get:

go get github.com/barkhayot/tempo

Usage

Basic Timer

package main

import (
	"time"
	"github.com/barkhayot/tempo"
)

func main() {
	timer := tempo.New()
	time.Sleep(2 * time.Second)
	timer.Stop()
}

Timer with Label and Threshold

package main

import (
	"time"
	"github.com/barkhayot/tempo"
)

func main() {
    timer := tempo.New(
        tempo.WithLabel("Process A"),
        tempo.WithThreshold(1*time.Second),
    )
    time.Sleep(3 * time.Second)
    timer.Stop()
}

Run with Timeout

package main

import (
	"time"
	"github.com/barkhayot/tempo"
)

func main() {
    ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
    defer cancel()

    tempo.RunWithTimeout(ctx, func() {
        time.Sleep(3 * time.Second) // Simulate slow function
    }, tempo.WithLabel("Timeout Example"))
}

About

A Go Package for Measuring Execution Time

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages