std_benchmark 0.1.0
Randomized benchmark and unittesting module
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
/** This module combines randomized unittests with benchmarking capabilites.
To gain appropriate test coverage and to test unexpected inputs, randomized
unittest are a possible approach.
Additionally, they lend itself for reproducible benchmarking and performance
monitoring.
*/
module std.experimental.randomized_unittest_benchmark;
import std.experimental.logger;
/// The following examples show an overview of the given functionalities.
unittest
{
void theFunctionToTest(int a, float b, string c)
{
// super expensive operation
auto rslt = (a + b) * c.length;
/* Pass the result to doNotOptimizeAway so the compiler
can not remove the expensive operation, and thereby falsify the
benchmark.
*/
doNotOptimizeAway(rslt);
debug
{
/* As the paramters to the function assume random values,
$(D benchmark) allows to quickly test function with various input
values. As the verification of computed value or state will at to
the runtime of the function to benchmark, it makes sense to only
execute these verifications in debug mode.
*/
assert(c.length ? true : true);
}
}
/* $(D benchmark) will run the function $(D theFunctionToTest) as often as
possible in 1 second. The function will be called with randomly selected
values for its parameters.
*/
benchmark!theFunctionToTest();
}
/// Ditto
unittest
{
/* This function takes to $(D Gen) types as parameter. These $(D Gen)
types are implicitly convertiable to the type given as the first template
type parameter. The second and thrid template parameter give the upper and
lower bound of the randomly selected value given to the parameter. This
allows to test functions which only work for a specific range of values.
*/
void theFunctionToTest(Gen!(int, 1, 5) a, Gen!(float, 0.0, 10.0) b)
{
// This will always be true
assert(a >= 1 && a <= 5);
assert(a >= 0.0 && a <= 10.0);
// super expensive operation
auto rslt = (a + b);
doNotOptimizeAway(rslt);
debug
{
assert(rslt > 1.0);
}
}
benchmark!theFunctionToTest();
}
- Registered by Robert Schadek
- 0.1.0 released 8 years ago
- burner/benchmark
- boost
- Copyright © 2015-2016, Robert burner Schadek
- Authors:
- Dependencies:
- none
- Versions:
-
0.3.3 2018-Jun-14 0.3.1 2017-Jun-01 0.3.0 2017-May-30 0.2.0 2017-May-04 0.1.2 2017-Feb-04 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
172 downloads total
-
- Score:
- 0.7
- Short URL:
- std_benchmark.dub.pm