I need to optimize some code that sorts a vector<pair<int, float >>
a where the pairs needs to be sorted on the float value. The vector will have an length between 0 and 5. I've been googling and reading up on sorting methods in C++ but cannot find any benchmarks on sorting tiny data sets. For the system it's important be as fast as possible as it's used for a real time blob tracking system.
Kind regards, Pollux
Insertion sort and Bubble sort are great for tiny data pairs.
Another option is to hard code the compare logic, with a couple if
statements.
Check out What is the fastest possible way to sort an array of 7 integers? for some ideas.
It makes no sense to read about benchmarks. You can read about and compare the complexity (Big-O) of algorithms, because it only depends on the algorithms themselves, but benchmarking is something that depends on too many factors.
You need to do the benchmarking for yourself, using the tools that you use, in the environment that matters to the users of your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With