sort-bench | A benchmark for sorting algorithms | Learning library
kandi X-RAY | sort-bench Summary
kandi X-RAY | sort-bench Summary
This a sort benchmark in support of this related blog post.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of sort-bench
sort-bench Key Features
sort-bench Examples and Code Snippets
Community Discussions
Trending Discussions on sort-bench
QUESTION
I have a vector of custom objects I'm sorting and noticed that the sort took a bit longer than expected. I decided to look further into it and adapted the code from this sort benchmark where instead of vector
, I'm sorting a vector
. The result is that it takes about 2.5 times longer to sort the vector of custom objects, measured using boost::chrono::steady_clock
as in the original benchmark code. This doesn't really make sense to me since the key is the same and the memory is already allocated by the time sorting starts. Why is that and does this affect other operations on such a vector, for example binary_search?
ANSWER
Answered 2017-Jun-23 at 15:42This doesn't really make sense to me since the key is the same and the memory is already allocated by the time sorting starts.
The difference is not due to allocations taking place. The size of the vector doesnt change while sorting, so there are no allocations. However, sort
has to copy the elements around to put them in the right place. And it shouldnt be too surprising that copying a double, 3 strings and an int takes more time than copying a single double.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install sort-bench
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page