diff --git a/cronexpr_test.go b/cronexpr_test.go index 1207eb3..9fbe49c 100644 --- a/cronexpr_test.go +++ b/cronexpr_test.go @@ -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) + } +}