unit_threaded.randomized

Modules

benchmark
module unit_threaded.randomized.benchmark
gen
module unit_threaded.randomized.gen
random
module unit_threaded.randomized.random

Examples

1 import core.thread : Thread;
2 import core.time : seconds;
3 
4 struct Foo
5 {
6     void superSlowMethod(int a, Gen!(int, -10, 10) b)
7         {
8             Thread.sleep(1.seconds / 250000);
9             doNotOptimizeAway(a);
10         }
11 }
12 
13 Foo a;
14 
15 auto del = delegate(int ai, Gen!(int, -10, 10) b) {
16     a.superSlowMethod(ai, b);
17 };
18 
19 benchmark!(del)();
1 import std.string : indexOf;
2 import std.experimental.logger;
3 
4 class SingleLineLogger : Logger
5 {
6     this()
7         {
8             super(LogLevel.info);
9         }
10 
11     override void writeLogMsg(ref LogEntry payload) @safe
12         {
13             this.line = payload.msg;
14         }
15 
16     string line;
17 }
18 
19 auto oldLogger = stdThreadLocalLog;
20 auto newLogger = new SingleLineLogger();
21 stdThreadLocalLog = newLogger;
22 scope (exit)
23     stdThreadLocalLog = oldLogger;
24 
25 static int failingFun(int a, string b)
26 {
27     throw new Exception("Hello");
28 }
29 
30 log();
31 benchmark!failingFun();
32 
33 assert(newLogger.line.indexOf("'a'") != -1);
34 assert(newLogger.line.indexOf("'b'") != -1);

Meta