[Issue 5794] New: std.datetime StopWatch (and perhaps benchmark) examples need a small fix

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 29 17:15:56 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5794

           Summary: std.datetime StopWatch (and perhaps benchmark)
                    examples need a small fix
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2011-03-29 17:12:24 PDT ---
The example code for StopWatch has this line:
sw.peek().msec, "[ms]");

This doesn't compile. This should be:
sw.peek().to!("msecs", int), "[ms]");

---

benchmark's description of the return value:
"Returns:
An array of n uints. Element at slot i contains the number of msecs spent in
calling the ith function times times. "

But the slot at i contains a TickDuration, not 'number of milliseconds'. You
still have to use to!("timemagnitude", returntype") to convert it to
milliseconds if you want to. E.g.:

    auto r = benchmark!(f0, f1, f2)(10_000_000);
    writeln( r[0].to!("msecs", int) );

Could you add that last line? It would really help in understanding the
example. Either that or add nice foreach loop like so:
    auto r = benchmark!(f0, f1, f2)(10_000_000);
    foreach (duration; r)
    {
        writeln( duration.to!("msecs", int) );
    }


A mention that TickDuration is defined in core.time would also be useful (it
took me a while to figure out where to find it).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list