Skip to content

timer pool for high performance time out control (pooled time.AfterFunc/time.NewTimer)

License

Notifications You must be signed in to change notification settings

hanjm/timerpool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc Go Report Card code-coverage

timerpool

timer pool for high performance time out control (pooled time.AfterFunc/time.NewTimer)

use example with context

ctx, cancel := context.WithCancel(parentCtx)
t := GetTimerWithAfterFunc(time.Second*5, cancel)
PutTimerWithAfterFunc(t)
cancel()

use example with timer.C

timer:=GetTimer(time.Second*5)
select {
case <-timer.C:
	// timeout
	PutTimer(timer)
	return
	// other case ...
}
PutTimer(timer)

benchmark result

go test -run TimeoutControl -bench TimeoutControl
goos: darwin
goarch: amd64
BenchmarkTimeoutControlViaContextWithTimeout-8                   2272261               523 ns/op
BenchmarkTimeoutControlViaContextWithCancelAndRawTimer-8         4370292               267 ns/op
BenchmarkTimeoutControlViaContextWithCancelAndTimerPool-8        4662602               253 ns/op
BenchmarkTimeoutControlViaRawTimer-8                             4829988               245 ns/op
BenchmarkTimeoutControlViaTimerPool-8                            9144037               126 ns/op

About

timer pool for high performance time out control (pooled time.AfterFunc/time.NewTimer)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages