mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
Merge pull request #263 from Eliyahu-Ravuna/patch-11
Suggested example for PER.4
This commit is contained in:
commit
21b6f6c82d
|
@ -9116,6 +9116,27 @@ If your program spends most of its time waiting for the web or for a human, opti
|
|||
|
||||
Simple code can be very fast. Optimizers sometimes do marvels with simple code
|
||||
|
||||
##### Example, good
|
||||
|
||||
// clear expression of intent, fast execution
|
||||
|
||||
vector v(100000);
|
||||
|
||||
for(auto& c : v)
|
||||
c = ~c;
|
||||
|
||||
##### Example, bad
|
||||
|
||||
// intended to be faster, but is actually slower
|
||||
|
||||
vector v(100000);
|
||||
|
||||
for(size_t i=0; i<v.size(); i+=sizeof(uint64_t))
|
||||
{
|
||||
uint64_t& quad_word = *reinterpret_cast<uint64_t*>(&v[i]);
|
||||
quad_word = ~quad_word;
|
||||
}
|
||||
|
||||
##### Note
|
||||
|
||||
???
|
||||
|
|
Loading…
Reference in New Issue
Block a user