ptimer

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ptimer provides a progress timer for iterative processes.

A timer prints how much time passed since its creation at exponentially growing time-points. Precisely, prints are triggered after i calls to Inc, if i has only one non-zero digit. That is: 1, 2, 3 .. 9, 10, 20, 30 .. 90, 100, 200, 300...

Output Format

For a regular use:

00:00:00.000000 (00:00:00.000000) message
|                          |         |
Total time since creation  |         |
                           |         |
Average time per call to Inc         |
                                     |
User-defined message ----------------|
(default message is number of calls to Inc)

When calling Done without calling Inc:

00:00:00.000000 message
Example
pt := New()
for i := 0; i < 45; i++ {
	time.Sleep(100 * time.Millisecond)
	pt.Inc()
}
pt.Done()
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Timer

type Timer struct {
	N int       // Current count, incremented with each call to Inc
	W io.Writer // Timer's output, defaults to stderr
	// contains filtered or unexported fields
}

A Timer measures time during iterative processes and prints the progress on exponential checkpoints.

func New

func New() *Timer

New returns a new timer that prints the current count on checkpoints.

func NewFunc

func NewFunc(f func(i int) string) *Timer

NewFunc returns a new timer that calls f with the current count on checkpoints, and prints its output.

func NewMessage added in v0.4.0

func NewMessage(msg string) *Timer

NewMessage returns a new timer that prints msg on checkpoints. A "{}" in msg will be replaced with the current count.

func (*Timer) Done

func (t *Timer) Done()

Done prints progress as if a checkpoint was reached.

func (*Timer) Inc

func (t *Timer) Inc()

Inc increments t's counter and prints progress if reached a checkpoint.

Jump to

Keyboard shortcuts

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