Onyx logo

Previous topic

onyx.util.dotdisplay – Tools and mix-in classes for DOT-based graphical display.

Next topic

onyx.util.flatten – Flatten nested structures

This Page

onyx.util.duration – Support for reproducible strings for floating point durations

Module attributes

NSECS_PER_SEC
Nanoseconds per second, 1000000000
NSECS_PER_10MILLISEC
Nanoseconds per 10 milliseconds, 10000000 – useful with 10 msec frames
NSECS_PER_MILLISEC
Nanoseconds per millisecond, 1000000
NSECS_PER_MICROSEC
Nanoseconds per microsecond, 1000
onyx.util.duration.time_usec_sec_str(duration_sec)

Format a duration (given as a number in seconds) into strings. Return a pair of strings where the first string gives the duration in microseconds and the second string gives the duration as decimal seconds with exactly six digits following the decimal point. Implementation avoids floating-point formatting issues by only using integer arithmetic.

>>> duration = 2478 / 1000000  # 2478 microseconds
>>> time_usec_sec_str(duration)
('2478', '0.002478')
>>> duration = 2478002478 / 100000  # 24780.02478 microseconds
>>> time_usec_sec_str(duration)
('24780024780', '24780.024780')

Use of module attribute NSECS_PER_SEC

>>> frame_duration_nsecs = 10000000
>>> num_frames = 247
>>> duration_secs = num_frames * frame_duration_nsecs / NSECS_PER_SEC
>>> time_usec_sec_str(duration_secs)
('2470000', '2.470000')

Use other module attributes

>>> print '10 millisec frames:', num_frames * frame_duration_nsecs // NSECS_PER_10MILLISEC
10 millisec frames: 247
>>> print 'millisecs:', num_frames * frame_duration_nsecs // NSECS_PER_MILLISEC
millisecs: 2470
>>> print 'microsecs:', num_frames * frame_duration_nsecs // NSECS_PER_MICROSEC
microsecs: 2470000
>>> print 'nanosecs:', num_frames * frame_duration_nsecs
nanosecs: 2470000000