Bug 5794 – std.datetime StopWatch (and perhaps benchmark) examples need a small fix

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-03-29T17:12:00Z
Last change time
2015-06-09T05:15:18Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2011-03-29T17:12:24Z
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).
Comment #1 by issues.dlang — 2011-03-30T14:54:18Z
I'll take a look at the StopWatch and benchmark comments and fix them if necessary. Most of that was written by SHOO (with a few tweaks by me - particularly when I renamed Ticks to TickDuration), and his English isn't always the best (it isn't his native language after all), so there could be some errors in there due to that or me or him just missing an error in the documentation. So, if you're aware of any obvious documentation mistakes in std.datetime, just add them here, and I'll take care of them. I'm currently overhauling std.datetime's unit tests though, so any fixes like that are likely to get done as part of that and so won't be done all that quickly (otherwise there's likely to be merge conflicts, which I don't want to deal with). Documentation fixes shouldn't be that critical though (important perhaps, but not critical). They'll definitely be fixed before the next release though.
Comment #2 by issues.dlang — 2011-05-05T01:26:05Z