Last active
October 13, 2020 09:38
-
-
Save tkm-kj/bcae9ec36018f37c53b85f1cc96a925f to your computer and use it in GitHub Desktop.
時間に応じて特定の数を大きくする(ゆっくり負荷をかけていきたい時に便利)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"time" | |
) | |
func main() { | |
startTime := time.Now() | |
var batchNum int64 = 10 | |
duration := 5 | |
multipleNum := 1.5 | |
currentPon := 0 | |
for { | |
now := time.Now() | |
diff := int(now.Sub(startTime).Seconds()) | |
if diff >= 60 { | |
break | |
} | |
mod := diff % duration | |
log.Printf("mod: %d", mod) | |
if mod == 0 { | |
pon := diff / duration | |
if pon > currentPon { // 同じ秒数で mod が0の時は何度も通る可能性があるので1回だけしか通らないようにして batchNum が上がりすぎないようにする | |
currentPon = pon | |
log.Printf("currentPon: %d", currentPon) | |
batchNum = int64(float64(batchNum) * multipleNum) | |
} | |
} | |
log.Printf("batchNum: %d", batchNum) | |
time.Sleep(time.Millisecond * 200) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment