Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
A reference/pointer is often 8 bytes long on the x64 architecture, so it's always pointless for primitive types unless you want to actually change them
Agreed. It's not too bad since vectors are cleverly resized under the hood. But you are right, it would be an improvement. Calling the constructor with the size would also be an option. While doing that you could also store the size in a variable and use that for the loop. That should be more efficient, since the compiler probably can't infer that lines.size() is a constant
Of Course we will see more "mov' assembler instructions, if we will work with references. Nevertheless the only way to measure optimization of "mov' instructions is time for the CPU to deal with them. As we can see from the benchmarking the CPU managed to sort out 7 additional mov instructions in less time. To summarise, to look only for the amount of generated instructions isn't a precise way to reach a conclusion of optimisation each time.
Hi. I have checked my solution using the chrono library in debug mode.
Passing by value: 577 microseconds.
Passing by reference: 386 microseconds.
Release mode
Passing by value: 270 microseconds.
Passing by reference: 271 microseconds.
Therefore I cant agree with your statement. If you have another idea how to practically measure the difference in another way - please tell me.
I have spotted an idea of yours in a book, however I try to check everything by myself.