Running Phobos unit tests in threads: I have data

Atila Neves via Digitalmars-d digitalmars-d at puremagic.com
Sat May 3 10:22:56 PDT 2014


I can reproduce the slower-with-threads issue without using my 
library. I've included the source file below and would like to 
know if other people see the same thing.

The Phobos modules are all called "ustd" because I 
couldn't/didn't know how to get this to work otherwise. So I 
copied the std/*.d files to a directory called ustd and changed 
their module declarations. Silly but it works. I'd love to know 
how to do this properly.

With this file, I consistenly get faster times with "-s" (for 
single-threaded) than without (multi-threaded):


import std.parallelism;
import std.getopt;


import ustd.array;
import ustd.ascii;
import ustd.base64;
import ustd.bigint;
import ustd.bitmanip;
import ustd.concurrency;
import ustd.container;
import ustd.cstream;


alias TestFunction = void function();

auto getTests(Modules...)() {
     TestFunction[] tests;
     foreach(mod; Modules) {
         foreach(test; __traits(getUnitTests, mod)) {
             tests ~= &test;
         }
     }
     return tests;
}



void main(string[] args) {
     bool single;
     getopt(args,
            "single|s", &single
         );

     enum tests = getTests!(
         ustd.array,
         ustd.ascii,
         ustd.base64,
         ustd.bigint,
         ustd.bitmanip,
         ustd.concurrency,
         ustd.container,
         ustd.cstream,
         );

     if(single) {
         foreach(test; tests) {
             test();
         }
     } else {
         foreach(test; tests.parallel) {
             test();
         }
     }
}


More information about the Digitalmars-d mailing list