Performance note: the lessThanCount(), greaterThanCount() and percentValue()
methods all sort the list of values stored in the Distribution instance. In
general it is thus best to add all the values you're interested in, then
call the results methods, so the list only needs to be sorted once.
Usage example:
importocean.math.Distribution;
importocean.io.Stdout;
importocean.time.StopWatch;
// Stopwatch instance.StopWatchsw;
// Create a distribution instance initialised to contain 10_000 values.// (The size can be extended, but it's set initially for the sake of// pre-allocation.)constnum_requests = 10_000;
autodist = newDistribution!(ulong)(num_requests);
// Perform a series of imaginary requests, timing each one and adding// the time value to the distributionfor ( inti; i < num_requests; i++ )
{
sw.start;
doRequest();
autotime = sw.microsec;
dist ~= time;
}
// Display the times taken by 50%, 66% etc of the requests.// (This produces output like apache bench.)constpercentages = [0.5, 0.66, 0.75, 0.8, 0.9, 0.95, 0.98, 0.99, 0.995, 0.999, 1];
foreach ( i, percentage; percentages )
{
autovalue = dist.percentValue(percentage);
Stdout.formatln("{,5:1}% <= {}μs", percentage * 100, value);
}
// Display the number of requests which took longer than 1ms.consttimeout = 1_000; // 1msautotimed_out = dist.greaterThanCount(timeout);
Stdout.formatln("{} requests ({,3:1}%) took longer than {}μs",
timed_out,
(cast(float)timed_out / cast(float)dist.length) * 100.0,
timeout);
// Clear distribution ready for next test.dist.clear;
Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
Alternatively, this file may be distributed under the terms of the Tango
3-Clause BSD License (see LICENSE_BSD.txt for details).
Helper class useful for producing apache bench style output about value distributions. For example:
Performance note: the lessThanCount(), greaterThanCount() and percentValue() methods all sort the list of values stored in the Distribution instance. In general it is thus best to add all the values you're interested in, then call the results methods, so the list only needs to be sorted once.
Usage example: