7 ms·
I usually use ChatGPT for such microbenchmarks (of course I design it myself and use LLM only as dumb code generator, so I don't need to remember how to measure
by codedokode 11mo ago
I usually use ChatGPT for such microbenchmarks (of course I design it myself and use LLM only as dumb code generator, so I don't need to remember how to measure time with nanosecond precision. I still have to add workarounds to prevent compiler over-optimizing the code). It's amazing, that when you get curious (for example, what is the fastest way to find an int in a small sorted array: using linear, binary search or branchless full scan?) you can get the answer in a couple minutes instead of spending 20-30 minutes writing the code manually.
By the way, the fastest way was branchless linear scan up to 32-64 elements, as far as I remember.
- lurquer 11mo agoIn C++, I’ve noticed that ChatGPT is fixated on unordered_maps. No matter the situation, when I ask what container would be wise to use, it’s always inordered_maps. Even when you tell it the container will have at most a few hundred elements (a size that would allow you to iterate their a vector to find what your are looking for before the unordered_map even has its morning coffee) it pushes the map… with enough prodding, it will eventually concede that a vector pretty much beats everything for small .size()’s.
- bmandale 11mo agoI agree with chatgpt here
- remexre 11mo agoisn't std::unordered_map famously slow, and you really want the hashmap from abseil, or boost, or folly, or [...]
- jcelerier 11mo ago> (a size that would allow you to iterate their a vector to find what your are looking for before the unordered_map even has its morning coffee) I don't know about this, whenever I've benchmarked it on my use cases, unordered_map started to become faster than vector at well below 100 elements
- themafia 11mo ago> I still have to add workarounds to prevent compiler over-optimizing the code Yet remembering how to measure time with nanosecond precision is the burden? > By the way, the fastest way was branchless linear scan up to 32-64 elements, as far as I remember. The analysis presented in the article is far more interesting, qualified, and useful that what you've produced here.