c++ - Iteration speed and element size -


i have std::vector filled following structures:

#define elementsize 8  struct element { int value; char size[elementsize - 4]; //1 char 1b in size - 4b int };  

the size of structure depends on defined elementsize, makes array of chars of specified size in structure.

i benchmarking average value of these structures in vector , love know reason why vector filled bigger structures in size takes longer iterate over.

for example vector 1 000 000 8b structures takes 1,7ms , same test 128b structures 12,7ms.

is big difference because of cache only? if so, explain why? or there other aspect can not see?

the structure 16 times bigger, should take 16 times longer iterate through. mathematically 12,7/1,7 = 7,47 times more, matches mathematically.

now imagine structure containing 128b elements structure containing 8b elements, same size. see 16 times larger?


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -