gtimer
gtimer copied to clipboard
Timer based on delayqueue
timer
Timer based on delayqueue
Design and implementation
The implementation is inspired by Java DelayQueue.java Portal: DelayQueue.java
The dependent structures are as follows:
timer -> delayqueue -> priorityqueue -> heap
Installation
Install:
go get -u github.com/vearne/gtimer
Import:
import "github.com/vearne/gtimer"
Quick Start
package main
import (
"fmt"
"github.com/vearne/gtimer"
"time"
)
func main() {
startTime := time.Now()
gtimer.Add(3*time.Second, func() {
fmt.Println(time.Since(startTime))
})
go func() {
time.Sleep(5 * time.Second)
gtimer.Stop()
}()
gtimer.Wait()
fmt.Println("---end---")
}
Performance
CPU Model Name
: 2.3 GHz Intel Core i5
CPU Processors
: 4
Memory
: 8GB
Benchmark Test Results
produce goroutines count | consume goroutines count | qps(per second) |
---|---|---|
1 | 1 | 285714 |
10 | 10 | 90090 |
10 | 100 | 89285 |
100 | 100 | 23255 |