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.

```
bash build-and-run.sh
g++ (Ubuntu 7.2.0-8ubuntu3) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

LDC - the LLVM D compiler (1.6.0):
  based on DMD v2.076.1 and LLVM 5.0.0
  built with LDC - the LLVM D compiler (1.6.0)
  Default target: x86_64-unknown-linux-gnu
  Host CPU: skylake
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_be - AArch64 (big endian)
    arm        - ARM
    arm64      - ARM64 (little endian)
    armeb      - ARM (big endian)
    nvptx      - NVIDIA PTX 32-bit
    nvptx64    - NVIDIA PTX 64-bit
    ppc32      - PowerPC 32
    ppc64      - PowerPC 64
    ppc64le    - PowerPC 64 LE
    thumb      - Thumb
    thumbeb    - Thumb (big endian)
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64     - 64-bit X86: EM64T and AMD64

=== Starting CPP version ===
Took 3.7583 to load 2000000 items. Gonna search in parallel...
5 4000000
6 4000000
2 4000000
0 4000000
1 4000000
7 4000000
4 4000000
3 4000000
Took 7.0247 to search

=== Starting D version ===
Took 1 sec, 506 ms, 672 μs, and 4 hnsecs to load 2000000 items. Gonna search in parallel...
3 4000000
4 4000000
2 4000000
6 4000000
7 4000000
5 4000000
1 4000000
0 4000000
Took 13 secs, 53 ms, 790 μs, and 3 hnsecs to search.
```
2. I'm on an 8 CPU box and I don't seem to hit 800% CPU with D version (max 720%). However I can get 800% CPU usage with the C++ version.

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.

Am I missing anything obvious here?

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

Cheers,
Arun

Reply via email to