3 ms·
> Because the point of this experimentation was to iterate over a list by accessing the memory and so to measure the time for each iteration, I had to be sure e
by sokoloff 9y ago
> Because the point of this experimentation was to iterate over a list by accessing the memory and so to measure the time for each iteration, I had to be sure every executed operation at each iteration was the most stripped-down set of instructions. Hard to be shorter than one cpu instruction for the given loop:
I’ll wager that the author didn’t look at the generated assembly as if that loop has only one CPU instruction, that instruction would be an increment, making the analysis of cache effects moot.
- mini_marcel 9y agoHi, thanks for reading. I'm sorry if this statement was not clear. It was of course outside the instructions necessary for the loop itself.
- reza_n 9y agoMost variables are registers, so it would have no effect on cache since there is no memory used to store the data. Only if that variable is pushed onto the stack/heap would it then consume cache. However, the size of the stack is much smaller when compared to the size of the data structures in play, so only a small percentage of cache is used for this control data.
- goldenkey 9y agoIn a handrolled assembly loop, the array pointer can be the iterator itself. In fact, this would be the ideal to compare the linked list version to, as the linked list would not have any kind of incremented iterator except for the pointer itself..
- mini_marcel 9y agoYes you're right! Since I was using the benchmark tools of go test, I had to use this increment. The main goal was to compare exactly same operations between each benchmarks. However, in the last test I ran, where I was walking indefinitely over the linked list, I guess I was closer to the behavior you're pointing out.