www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18398] New: std.datetime.stopwatch documented examples could


          Issue ID: 18398
           Summary: std.datetime.stopwatch documented examples could be
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: n8sh.secondary hotmail.com

Someone using `std.datetime.stopwatch` probably wants to use it to obtain a
time in milliseconds or some other unit of time but none of the example code on
the page involves converting a core.time.Duration. This makes the examples less
helpful to a newcomer than they could be.

Proposed addition:

    /// Measure a time in milliseconds, microseconds, or nanoseconds
     safe nothrow  nogc unittest
        auto sw = StopWatch(AutoStart.no);
        // ... Insert operations to be timed here ...

        long msecs = sw.peek().total!"msecs";
        long usecs = sw.peek().total!"usecs";
        long nsecs = sw.peek().total!"nsecs";

        assert(usecs >= msecs * 1000);
        assert(nsecs >= usecs * 1000);

Feb 08 2018