Skip to content

Instantly share code, notes, and snippets.

@klizhentas
Created November 8, 2014 05:22
Show Gist options
  • Save klizhentas/300e19bbada120db2454 to your computer and use it in GitHub Desktop.
Save klizhentas/300e19bbada120db2454 to your computer and use it in GitHub Desktop.
Benchmark
package main
import (
"fmt"
"log"
"net/http"
"time"
"github.com/mailgun/metrics"
"github.com/mailgun/timetools"
_ "net/http/pprof"
)
func main() {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
s, err := metrics.NewStatsdWithOptions("localhost:8125", "perf", metrics.StatsdOptions{UseBuffering: true})
if err != nil {
log.Fatalf("Error %v\n", err)
}
tm := &timetools.RealTime{}
a := tm.UtcNow()
prev := 0
for i := 0; i < 100000000000000; i++ {
s.Inc(s.Metric("hello", "a", "hellooooo"), 1, 1)
if i%1000000 == 0 {
tdiff := tm.UtcNow().Sub(a) / time.Millisecond
a = tm.UtcNow()
diff := i - prev
prev = i
fmt.Printf("Emitted %d metrics, speed: %0.1f/second\n", i, 1000*(float64(diff)/float64(tdiff)))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment