added benchmarking, as per #5
This commit is contained in:
parent
5442b2bfef
commit
164843d2d0
|
@ -132,6 +132,8 @@ func TestExpressions(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
func TestZero(t *testing.T) {
|
||||
from, _ := time.Parse("2006-01-02", "2013-08-31")
|
||||
next := cronexpr.MustParse("* * * * * 1980").Next(from)
|
||||
|
@ -150,6 +152,8 @@ func TestZero(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
func TestNextN(t *testing.T) {
|
||||
expected := []string{
|
||||
"Sat, 30 Nov 2013 00:00:00",
|
||||
|
@ -172,3 +176,39 @@ func TestNextN(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var benchmarkExpressions = []string{
|
||||
"* * * * *",
|
||||
"@hourly",
|
||||
"@weekly",
|
||||
"@yearly",
|
||||
"30 3 15W 3/3 *",
|
||||
"30 0 0 1-31/5 Oct-Dec * 2000,2006,2008,2013-2015",
|
||||
"0 0 0 * Feb-Nov/2 thu#3 2000-2050",
|
||||
}
|
||||
var benchmarkExpressionsLen = len(benchmarkExpressions)
|
||||
|
||||
func BenchmarkParse(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = cronexpr.MustParse(benchmarkExpressions[i%benchmarkExpressionsLen])
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNext(b *testing.B) {
|
||||
exprs := make([]*cronexpr.Expression, benchmarkExpressionsLen)
|
||||
for i := 0; i < benchmarkExpressionsLen; i++ {
|
||||
exprs[i] = cronexpr.MustParse(benchmarkExpressions[i])
|
||||
}
|
||||
from := time.Now()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
expr := exprs[i%benchmarkExpressionsLen]
|
||||
next := expr.Next(from)
|
||||
next = expr.Next(next)
|
||||
next = expr.Next(next)
|
||||
next = expr.Next(next)
|
||||
next = expr.Next(next)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue