Skip to content

tic() should use monotonic clock #2464

@jayschwa

Description

@jayschwa

tic() and friends use the system time for measuring duration. This can be problematic if the system time is changed between measurements:

tic()
toc()
now = int32(time())
tic()
# move system time backwards
run(`date --set="@$(now-60)"`)
toc()
# restore system time
run(`date --set="@$(now)"`)

yields

elapsed time: 0.01815319061279297 seconds
Mon Mar  4 16:05:30 EST 2013
elapsed time: -60.13567399978638 seconds
Mon Mar  4 16:06:30 EST 2013

It would be better to use a monotonic clock for any place where duration is being measured, independent of datetime. Examples:
http://linux.die.net/man/3/clock_gettime
http://docs.python.org/3/library/time.html#time.monotonic

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions