1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

time: time.wait() => time.sleep()

This commit is contained in:
Alexander Medvednikov
2021-02-27 20:41:06 +03:00
parent be4a2e17d3
commit 3a2d696fac
42 changed files with 76 additions and 67 deletions

View File

@ -7,7 +7,7 @@ fn test_stopwatch_works_as_intended() {
mut sw := time.new_stopwatch({})
// sample code that you want to measure:
println('Hello world')
time.wait(1 * time.millisecond)
time.sleep(1 * time.millisecond)
//
println('Greeting the world took: ${sw.elapsed().nanoseconds()}ns')
assert sw.elapsed().nanoseconds() > 0
@ -16,18 +16,18 @@ fn test_stopwatch_works_as_intended() {
fn test_stopwatch_time_between_pause_and_start_should_be_skipped_in_elapsed() {
println('Testing pause function')
mut sw := time.new_stopwatch({})
time.wait(10 * time.millisecond) // A
time.sleep(10 * time.millisecond) // A
eprintln('Elapsed after 10ms nap: ${sw.elapsed().milliseconds()}ms')
assert sw.elapsed().milliseconds() >= 8 // sometimes it sleeps for 9ms on windows..
sw.pause()
time.wait(10 * time.millisecond)
time.sleep(10 * time.millisecond)
eprintln('Elapsed after pause and another 10ms nap: ${sw.elapsed().milliseconds()}ms')
assert sw.elapsed().milliseconds() >= 8
$if stopwatch ? {
assert sw.elapsed().milliseconds() < 20
}
sw.start()
time.wait(10 * time.millisecond) // B
time.sleep(10 * time.millisecond) // B
eprintln('Elapsed after resume and another 10ms nap: ${sw.elapsed().milliseconds()}ms')
assert sw.elapsed().milliseconds() >= 18
$if stopwatch ? {