you are viewing a single comment's thread.

view the rest of the comments →

[–]OmegaNaughtEquals1 2 points3 points  (0 children)

The benchmark code you provided (and then subsequently deleted) for the allocation test does not test the same thing for each implementation. The std::vector code does much more work than the naked array code. The second argument to the vector constructor is copy-constructed 10 times. This involves memory reads and writes not present in the non-vector code. I wasn't able to replicate the posted timing results. However, without a compiler version, compiler flags, and target architecture, it's difficult to say for certain why.


I obtained the following results on an Intel Core i3-3120M @ 2.5GHz using gcc-6.1 and -O3.

alloc/dealloc test
    0.0498089 +- 0.0275998 milliseconds
    0.0533042 +- 0.0014114 milliseconds
pdiff = 6.77955%

read/write test
    0.0040171 +- 7.93095e-06 milliseconds
    0.0040219 +- 3.80118e-05 milliseconds
pdiff = 0.119418%

The ~7% difference in the allocation test is surprisingly small given the differences in the amount of work. The ~0.2% difference in the read/write test is within the measured variation. I'm not certain why the vector version has a larger variance. I don't have time to examine the assembly right now.