Added some tests involving phobos.
This commit is contained in:
parent
5d96b5e3ca
commit
ed4e619228
6 changed files with 102 additions and 1 deletions
3
tests/app_7/CMakeLists.txt
Normal file
3
tests/app_7/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
# A more complex library test.
|
||||
ADD_EXECUTABLE( app_7 app_7.d )
|
||||
ADD_TEST( app_7 app_7 )
|
85
tests/app_7/app_7.d
Normal file
85
tests/app_7/app_7.d
Normal file
|
@ -0,0 +1,85 @@
|
|||
import std.stdio;
|
||||
import core.thread;
|
||||
import std.perf;
|
||||
|
||||
// Yield count should be larger for a
|
||||
// more accurate measurment, but this
|
||||
// is just a unit tests, so don't spin
|
||||
// for long
|
||||
immutable uint yield_count = 1000;
|
||||
immutable uint worker_count = 10;
|
||||
|
||||
uint stack_check()
|
||||
{
|
||||
uint x;
|
||||
asm
|
||||
{
|
||||
mov x,ESP;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
void fiber_func()
|
||||
{
|
||||
uint i = yield_count;
|
||||
while( --i ) Fiber.yield();
|
||||
}
|
||||
|
||||
void thread_func()
|
||||
{
|
||||
uint i = yield_count;
|
||||
while( --i ) Thread.yield();
|
||||
}
|
||||
|
||||
void fiber_test()
|
||||
{
|
||||
Fiber[worker_count] fib_array;
|
||||
|
||||
foreach( ref f; fib_array )
|
||||
f = new Fiber( &fiber_func );
|
||||
|
||||
auto timer = new PerformanceCounter;
|
||||
|
||||
uint i = yield_count;
|
||||
|
||||
// fibers are cooperative and need a driver loop
|
||||
timer.start();
|
||||
bool done;
|
||||
do
|
||||
{
|
||||
done = true;
|
||||
foreach( f; fib_array )
|
||||
{
|
||||
f.call();
|
||||
if( f.state() != f.State.TERM )
|
||||
done = false;
|
||||
}
|
||||
} while( !done );
|
||||
timer.stop();
|
||||
|
||||
writeln( "Elapsed time for ", worker_count, " workers times ", yield_count, " yield() calls with fibers = ",
|
||||
timer.milliseconds, "ms" );
|
||||
}
|
||||
|
||||
void thread_test()
|
||||
{
|
||||
Thread[worker_count] thread_array;
|
||||
|
||||
foreach( ref t; thread_array )
|
||||
t = new Thread( &thread_func );
|
||||
|
||||
auto timer = new PerformanceCounter;
|
||||
timer.start();
|
||||
foreach( t; thread_array )
|
||||
t.start();
|
||||
thread_joinAll();
|
||||
timer.stop();
|
||||
writeln( "Elapsed time for ", worker_count, " workers times ", yield_count, " yield() calls with threads = ",
|
||||
timer.milliseconds, "ms" );
|
||||
}
|
||||
int main()
|
||||
{
|
||||
fiber_test();
|
||||
thread_test();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue