curl2info/crontab_test.go

89 lines
2.0 KiB
Go
Raw Normal View History

2018-12-02 19:18:42 +00:00
package curl2info
import (
"fmt"
"log"
2018-12-03 12:01:19 +00:00
"runtime"
2018-12-02 19:18:42 +00:00
"testing"
2018-12-03 11:22:43 +00:00
"time"
2018-12-02 19:18:42 +00:00
)
2018-12-03 11:22:43 +00:00
// type LRValue struct {
// left, right int
// }
func TestParseCrontab(t *testing.T) {
// crontab := "0-5/2,7-30/3,30,35,40-^1 * * * *" //(秒) 分 时 号(每月的多少号, 要注意月可可能性) 星期几(每个星期的) /每 ,列表 -范围
2018-12-05 03:57:16 +00:00
crontab := "* * * * *"
t.Error("")
// t.Error(NewCrontab(crontab))
2018-12-03 11:22:43 +00:00
2018-12-04 20:25:40 +00:00
var s []*TrieYear
PrintMemUsage()
2018-12-03 11:22:43 +00:00
2018-12-05 03:57:16 +00:00
for i := 0; i < 100; i++ {
2018-12-04 20:25:40 +00:00
ty := newTrieYear(2018)
ty.FromCrontab(NewCrontab(crontab))
s = append(s, ty)
}
2018-12-03 11:22:43 +00:00
2018-12-04 20:25:40 +00:00
ty := newTrieYear(2018)
cron := NewCrontab(crontab)
ty.FromCrontab(cron)
2018-12-05 03:57:16 +00:00
t1 := time.Now()
2018-12-04 20:25:40 +00:00
log.Println(ty.GetPlanTime(cron, time.Now(), 10))
2018-12-05 03:57:16 +00:00
log.Println(time.Since(t1))
cron.CreateYearPlan()
cur := time.Now().Add(time.Minute * 2)
for i := 0; i < 510; i++ {
if i >= 499 {
// log.Println("skip:", cron.SkipPlans, len(cron.SkipPlans))
log.Println(cur, "will:", cron.WillPlans[0:10], len(cron.WillPlans))
log.Println("skip:", cron.SkipPlans)
}
log.Println(cron.TimeUp(cur))
cur = cur.Add(time.Minute * 1) // 模拟出来的分绝对一分钟, 程序损耗会多几毫秒
// time.Sleep(time.Minute * 1)
}
2018-12-03 11:22:43 +00:00
// for {
2018-12-03 11:22:43 +00:00
// i := ty.TimeUp()
// if i != nil {
// if i.GetStatus() {
// spew.Dump(i)
// log.Println(time.Now())
// break
// }
2018-12-03 11:22:43 +00:00
// }
// time.Sleep(time.Millisecond * 200)
2018-12-03 11:22:43 +00:00
// }
2018-12-03 12:01:19 +00:00
PrintMemUsage()
}
2018-12-03 18:55:34 +00:00
func TestCrontabPlus(t *testing.T) {
// crontab := "0-5/2,7-30/3,30,35,40-^1 * * * *" //(秒) 分 时 号(每月的多少号, 要注意月可可能性) 星期几(每个星期的) /每 ,列表 -范围
// crondata := NewCrontab("*22 * * * *")
2018-12-03 12:01:19 +00:00
}
func PrintMemUsage() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
fmt.Printf("\tNumGC = %v\n", m.NumGC)
}
func bToMb(b uint64) uint64 {
return b / 1024 / 1024
2018-12-02 19:18:42 +00:00
}