Create many objects using threads
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon May 5 15:11:38 PDT 2014
On 05/05/2014 02:38 PM, Kapps wrote:
> I think that the GC actually blocks when
> creating objects, and thus multiple threads creating instances would not
> provide a significant speedup, possibly even a slowdown.
Wow! That is the case. :)
> You'd want to benchmark this to be certain it helps.
I did:
import std.range;
import std.parallelism;
class C
{}
void foo()
{
auto c = new C;
}
void main(string[] args)
{
enum totalElements = 10_000_000;
if (args.length > 1) {
foreach (i; iota(totalElements).parallel) {
foo();
}
} else {
foreach (i; iota(totalElements)) {
foo();
}
}
}
Typical run on my system for "-O -noboundscheck -inline":
$ time ./deneme parallel
real 0m4.236s
user 0m4.325s
sys 0m9.795s
$ time ./deneme
real 0m0.753s
user 0m0.748s
sys 0m0.003s
Ali
More information about the Digitalmars-d-learn
mailing list