mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
time: complete doc (#8070)
This commit is contained in:
@@ -7,6 +7,7 @@ pub struct StopWatchOptions {
|
||||
auto_start bool = true
|
||||
}
|
||||
|
||||
// StopWatch is used to measure elapsed time.
|
||||
pub struct StopWatch {
|
||||
mut:
|
||||
elapsed u64
|
||||
@@ -15,6 +16,7 @@ pub mut:
|
||||
end u64
|
||||
}
|
||||
|
||||
// new_stopwatch initializes a new StopWatch with the current time as start.
|
||||
pub fn new_stopwatch(opts StopWatchOptions) StopWatch {
|
||||
mut initial := u64(0)
|
||||
if opts.auto_start {
|
||||
@@ -27,22 +29,25 @@ pub fn new_stopwatch(opts StopWatchOptions) StopWatch {
|
||||
}
|
||||
}
|
||||
|
||||
// start Starts the timer. If the timer was paused, restarts counting.
|
||||
// start starts the stopwatch. If the timer was paused, restarts counting.
|
||||
pub fn (mut t StopWatch) start() {
|
||||
t.start = sys_mono_now()
|
||||
t.end = 0
|
||||
}
|
||||
|
||||
// restart restarts the stopwatch. If the timer was paused, restarts counting.
|
||||
pub fn (mut t StopWatch) restart() {
|
||||
t.start = sys_mono_now()
|
||||
t.end = 0
|
||||
t.elapsed = 0
|
||||
}
|
||||
|
||||
// stop stops the timer, by setting the end time to the current time.
|
||||
pub fn (mut t StopWatch) stop() {
|
||||
t.end = sys_mono_now()
|
||||
}
|
||||
|
||||
// pause resets the `start` time and adds the current elapsed time to `elapsed`.
|
||||
pub fn (mut t StopWatch) pause() {
|
||||
if t.start > 0 {
|
||||
if t.end == 0 {
|
||||
|
||||
Reference in New Issue
Block a user