std.datetime
Platform-independent high precision StopWatch. This module provide:- StopWatch
- Benchmarks
- Some helper functions
Boost License 1.0. Authors:
Kato Shoichi
- System clock time.
This type maintains the most high precision ticks of system clock in each
environment.
(For StopWatch)
- Ticks that is counted per 1[s]. Confirm that it is not 0, to examine whether you can use Ticks.
- Ticks when application begins.
- Unknown value for Ticks You can convert this value into number of seconds by dividing it by ticksPerSec.
- [s] as integer or real number
Attention:
This method truncate the number of digits after decimal point. - [s] as real number
- [s] as integer
- Create Ticks from [s] as integer
- [ms] as integer or real number
- [ms] as real number
- [ms] as integer
- Create Ticks from [ms] as integer
- [us] as integer or real number
- [us] as real number
- [us] as integer
- Create Ticks from [us] as integer
- operator overroading "-=, +="
BUG:
This should be return "ref Ticks", but bug2460 prevents that. - operator overroading "-, +"
- operator overroading "=="
- operator overroading "<, >, <=, >="
- operator overroading "*=, /="
- operator overroading "*", "/"
- operator overroading "/"
- Special type for constructor
- StopWatch's AutoStart flag
- StopWatch measures time highly precise as possible.
This class uses performance counter.
On Windows, This uses QueryPerformanceCounter.
For Posix, This uses clock_gettime if available, gettimeofday otherwise.
But this has dispersion in accuracy by environment.
It is impossible to remove this dispersion. This depends on multi task
system for example overhead from change of the context switch of the thread.
Usage is here:
Example:
void foo() { StopWatch sw; static immutable N = 100; Ticks[N] times; Ticks last = Ticks.fromSeconds(0); foreach (i; 0..N) { sw.start(); // start/resume mesuring. foreach (Unused; 0..1000000) bar(); sw.stop(); // stop/pause mesuring. // Return value of peek() after having stopped are the always same. writeln((i+1)*1000000, " times done, lap time: ", sw.peek().msec, "[ms]"); times[i] = sw.peek() - last; last = sw.peek(); } real sum = 0; // When you want to know the number of seconds of the fact, // you can use properties of Ticks. // (seconds, mseconds, useconds, interval) foreach (e; times) sum += e.interval; writeln("Average time: ", sum/N, "[s]"); }
- this(AutoStart autostart);
- auto start with constructor
- Reset the time measurement.
- Start the time measurement.
- Stop the time measurement.
- Peek Ticks of measured time.
- Ticks of system time.
- Ticks when application begin running.
- Benchmarks code for speed assessment and comparison.
Parameters:
Returns:fun aliases of callable objects (e.g. function names). Each should take no arguments. times The number of times each function is to be executed.
An array of n uints. Element at slot i contains the number of milliseconds spent in calling the ith function times times. Examples:int a; void f0() { } void f1() { auto b = a; } void f2() { auto b = to!(string)(a); } auto r = benchmark!(f0, f1, f2)(10_000_000);
- Return value of benchmark with two functions comparing.
- Evaluation value This return the evaluation value of performance as the ratio that is compared between BaseFunc's time and TargetFunc's time. If performance is high, this returns a high value.
- The time required of the target function
- The time required of the base function
- Benchmark with two functions comparing.
Parameters:
Examples:baseFunc The function to become the base of the speed. targetFunc The function that wants to measure speed. times The number of times each function is to be executed. void f1() { // ... } void f2() { // ... } void main() { auto b = comparingBenchmark!(f1, f2, 0x80); writeln(b.point); }
- Scope base measuring time.
When a value that is returned by this function is destroyed,
func will run.
func is unaly function that requires Ticks.
Examples:
writeln("benchmark start!"); { auto mt = measureTime!((a){assert(a.seconds);}); doSomething(); } writeln("benchmark end!");