Bug 12067 – std.datetime.measureTime() has incomplete example, and does not work

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-02T20:59:00Z
Last change time
2017-07-10T15:05:12Z
Assigned to
nobody
Creator
bugzilla

Comments

Comment #0 by bugzilla — 2014-02-02T20:59:43Z
Presumably the function http://dlang.org/phobos/std_datetime.html#.measureTime is supposed to be for measuring the elapsed time of some code, i.e. for benchmarking it. But: 1. The example given is a code fragment, the user is left to guess what else might be needed to get it to work. 2. The user most likely wants to print the elapsed time. The example gives no clue how to do that. 3. Guessing at what is needed to make a complete program, the program fails to link: ----------------------------- import std.datetime; import std.stdio; void main() { writeln("benchmark start!"); { auto mt = measureTime!((a){assert(a.seconds);}); doSomething(); } writeln("benchmark end!"); } ------------------------------ C:\mars>\dmd2\windows\bin\dmd foo OPTLINK (R) for Win32 Release 8.00.13 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html foo.obj(foo) Error 42: Symbol Undefined _D3foo4mainFZv46__T14__funcliteral1TS4core4time12TickDurationZ14__funcli teral1FS4core4time12TickDurationZv --- errorlevel 1
Comment #1 by bugzilla — 2014-02-02T21:03:38Z
Forgot to mention, the type of function parameter 'a' needs to be documented.
Comment #2 by bugzilla — 2014-02-02T22:06:55Z
(In reply to comment #1) > Forgot to mention, the type of function parameter 'a' needs to be documented. Jonathan suggested that adding 'TickDuration' as the type of 'a' fixes the linking problem, and indeed it does.
Comment #3 by bugzilla — 2014-02-02T23:20:39Z
Comment #4 by github-bugzilla — 2014-02-04T02:01:18Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/6c08a1e526cb1ad0b875876924c7f10d7ca6cfd9 Fix issue 12067. Note that the measureTime examples do not use documented unittest blocks, because that doesn't work when the documentation is split out into a separate version(StdDDoc) section. https://github.com/D-Programming-Language/phobos/commit/ef000e8150ffaf0030ea5c62c311a23e5067d139 Merge pull request #1907 from jmdavis/12067 Fix issue 12067.