On Friday, 8 December 2017 at 07:34:53 UTC, Arun Chandrasekaran wrote:
I was wondering if std.container.array.Array supports threadsafe parallel reads similar to std::vector. I've created a small program for demonstration https://github.com/carun/parallel-read-tester

It works fine with just couple of problems though:

1. D version takes way too long compared to C++ version.

My mistake (IO bottleneck, std.stdio.write is probably flushing?)! The timings are now close enough, in the order of milliseconds. This is not just with one run, but multiple runs. (I should probably test this on a Xeon server).

=== Starting CPP version ===
Took 3.79253 to load 2000000 items. Gonna search in parallel...
4 400000000
1 400000000
3 400000000
2 400000000
6 400000000
7 400000000
5 400000000
0 400000000
Took 6.28018 to search

=== Starting D version ===
Took 1 sec, 474 ms, 869 μs, and 4 hnsecs to load 2000000 items. Gonna search in parallel...
0 400000000
1 400000000
2 400000000
7 400000000
6 400000000
4 400000000
3 400000000
5 400000000
Took 6 secs, 472 ms, 467 μs, and 8 hnsecs to search.

The one that puzzles me is, what's wrong with the CPP version? :) Why is it slow loading the gallery (more than twice as slow as the D counterpart)? I thought std::vector::emplace_back should do a decent job. RVO in D?

2. Introducing a string in the struct Data results in "std.container.Array.reserve failed to allocate memory", whereas adding a similar std::string in the C++ struct seems to work fine.
Couldn't find the reason!

Am I missing anything obvious here?

Also why doesn't std.container.array support an equivalent of std::vector::erase?

Reply via email to