Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example code isn't working #2

Open
dancapper opened this issue Jul 16, 2018 · 0 comments
Open

Example code isn't working #2

dancapper opened this issue Jul 16, 2018 · 0 comments

Comments

@dancapper
Copy link

dancapper commented Jul 16, 2018

I copied the example code into a file, build with Go 1.1.0.3 and execute. The results are that it returns all zeros. (after I fixed some missing closing brackets in the example code)

$ go build average-example.go

$ go version
go version go1.10.3 windows/amd64

$ ./average-example.exe
Average of last  1m: 0.000000
Average of last  5m: 0.000000
Average of last 15m: 0.000000

Counter has a total of 0 over 0 samples
$

average_example.go:


package main

import (
	"fmt"
	"time"

	"github.com/prep/average"
)

func main() {
	// Create a SlidingWindow that has a window of 15 minutes, with a
	// granulity of 1 minute.
	sw := average.MustNew(15*time.Minute, time.Minute)
	defer sw.Stop()

	// Do some work.
	sw.Add(15)
	// Do some more work.
	sw.Add(22)
	// Do even more work.
	sw.Add(22)

	fmt.Printf("Average of last  1m: %f\n", sw.Average(time.Minute))
	fmt.Printf("Average of last  5m: %f\n", sw.Average(5*time.Minute))
	fmt.Printf("Average of last 15m: %f\n\n", sw.Average(15*time.Minute))

	total, numSamples := sw.Total(15 * time.Minute)
	fmt.Printf("Counter has a total of %d over %d samples", total, numSamples)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant