I’m working with a library that uses “memcpy” to simulate dynamical storage data structure with direct access. It’s important to note that I’m working on numerical operations that result with small data sets. How can I determine if a linked list would be more appropriate than memcpy in terms of efficiency?
From what I’ve found in the literature and online, benchmarks are considered quite evil.
I’m dealing with around 30 elements (from experience) of small size (3 component vectors : points in space).
What would you use in this case:
1) memcpy + direct access
2) linked list + linear search time
Thanks!
If you really care that much about performance, you should measure it, i.e. benchmark your code (this is not evil, it is common practice; what is evil is premature optimization).
But be aware that, at least with recent GCC (e.g. GCC 4.6) on GNU/Linux and when optimized by at least -O2,
memcpy&memsetare semi-magically (thru__builtin_memcpyor similar tricks) transformed to quite efficient code.And for large set of small data elements, I would guess that caching consideration are dominant w.r.t. performance.