Boost logo

Boost :

Subject: Re: [boost] What's wrong with this benchmark
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2016-02-18 02:51:17


I think there is definitely something not quite right.

One thing I notice is that the line:
        sample.push_back(get_clock() - base_clock);
Is being timed.
Which could potentially access a new memory page I think.

In pin_thread you have _MSVC_VER instead of _MSC_VER

Hacking up std::vector and adding a push_back_reserved that does no
bounds checks I get consistently very strange timings.
(Code included at the bottom to make it obvious that the latter should
be no slower).

X std::vector::push_back
0 0
100 765.360000
200 1537.260000
400 3037.950000
800 6008.280000
1600 11905.150000
3200 23950.320000
6400 48064.600000
12800 96178.470000
25600 190637.270000
51200 379025.420000
102400 757784.880000
204800 1514584.120000
409600 3026480.680000
819200 6050654.130000

X std::vector::push_back_reserved
0 0
100 938.090000
200 1936.380000
400 3704.400000
800 7274.170000
1600 14307.310000
3200 28550.140000
6400 56835.310000
12800 113579.430000
25600 226906.070000
51200 453802.040000
102400 911835.760000
204800 1819723.520000
409600 3639619.650000
819200 7281897.560000

My simpler, and I'm sure in many ways inferior benchmark, shows much
more believable results.

http://codepad.org/SBZ4rbqo

Running 1 test case...
std::vector<uint32_t>::push_back_reserved 4.88
std::vector<uint32_t>::push_back 6.31
bst::devector<uint32_t>::push_back 5.37
bst::vector<uint32_t>::push_back 7.22

void push_back(value_type&& _Val)
{ // insert by moving into element at end
     if (_Inside(_STD addressof(_Val))) { // push back an element
         size_type _Idx = _STD addressof(_Val) - this->_Myfirst();
         if (this->_Mylast() == this->_Myend())
             _Reserve(1);
         _Orphan_range(this->_Mylast(), this->_Mylast());
         this->_Getal().construct(this->_Mylast(),
             _STD forward<value_type>(this->_Myfirst()[_Idx]));
         ++this->_Mylast();
     } else { // push back a non-element
         if (this->_Mylast() == this->_Myend())
             _Reserve(1);
         _Orphan_range(this->_Mylast(), this->_Mylast());
         this->_Getal().construct(this->_Mylast(),
             _STD forward<value_type>(_Val));
         ++this->_Mylast();
     }
}

void push_back_reserved( value_type&& _Val )
{
     this->_Getal().construct( this->_Mylast(),
         _STD forward<value_type>( _Val ) );
     ++this->_Mylast();
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk