This feels like a very newbie question, but I suddenly find myself clueless. I’m trying to profile a c application that does a lot of memory copies, and there is an option for me to reduce that number (requires some re-design). I’m trying to realize if it’s worth it, but I have no idea what resource it will affect, or how to monitor it.
If someone knows what resource (and how to monitor it in Linux), and/or has a reference to a section in Agner or any other optimization manual I would very much appreciate it. Thanks.
Advertisement
Answer
memcpy
uses the CPU in order to copy memory from one buffer to the other. Generally speaking, code doing lots of memcpy
will be CPU bound.
With that said, some of the underlying design might make this different. In particular, if you’re doing a lot of memory copying, it might be that you are using memory once and throwing it away. If that’s the case, you are making poor use of the CPU’s data cache. Switching to an algorithm that keeps the memory where it is may give you a huge benefit on that front.
As for profiling, I know valgrind has a tool for checking cache efficiency. Maybe others too.