diff options
author | Adam Spragg <adam@spra.gg> | 2023-01-17 14:52:00 +0000 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2023-01-17 16:32:18 +0000 |
commit | 966745e79b871c576b5ebdabea526b7acd3a4251 (patch) | |
tree | 9ba96c9873ebcfacc56e768febc365c576b1c4dd | |
parent | aa2614c322cda0be1ff26644d7dead45100ea358 (diff) |
Puzzle 16: Attempt to speed up the "reverse" function
Even though we change from 3 small memcpy()s per 2 items, to 1 small
memcpy() per item plus 1 big memcpy(), it goes slower?
(On part 1 of the puzzle with a 40 minute limit, the timing goes from
6.6s to 6.8s, average of 5 runs.)
Leave commented out for now.
-rw-r--r-- | 16.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -34,6 +34,16 @@ qreverse(void * base, size_t nmemb, size_t size) if (nmemb < 2) return; +#if 0 // This goes slower?!? + if (nmemb < BUFSIZ / size) { + char tmp[nmemb * size]; + memcpy(tmp, base, nmemb * size); + for (i = 0; i < nmemb; ++i) + memcpy(base + i * size, tmp + (nmemb - 1 - i) * size, size); + return; + } +#endif + for (i = 0, j = nmemb - 1; i < j; ++i, --j) qswap(base, size, i, j); } |