Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
If you click in the 'Output' section (next to 'Instructions') you can find the time your code took on the top left hand corner above 'Test Results:'.
Hello. Where can I see the speed of code to compare solutions?
This solution is very slow, look at the rock4259 solution, it is an order of magnitude faster. 572 ns and 35 ns respectively.
Great solution! According to my estimates, this solution is 7 times faster than the mouloud solution which is in 1st place.
One question, why do you need the last
if
why not just return the comparison result? :-)Thank you! <3
In my opinion, this is the most effective solution.
Each time this function is called, a container is created, this significantly slows down the function.
The benchmark shows CPU: no static, just const - 465 ns, static const - 97.7 ns
"std::map is a sorted associative container that contains key-value pairs with unique keys. Keys are sorted by using the comparison function Compare."
look at https://en.cppreference.com/w/cpp/container/map
Simple benchmark. V1 - my solution, V2 - this solution, V3 - antekm solution.
Empty array (CPU, Iterations): V1 - (1.28 ns, 535'516'003), V2 - (47'945 ns, 14'268), V3 - (4.81 ns 144'987'229).
Not empty array from tests (CPU, Iterations): V1 - (47.8 ns, 14'700'160), V2 - (47'874 ns, 14'477), V3 - (63.7 ns, 10'709'026)
May be I am wrong, but it seems that this solution is 1'000 times slower!
P.S. This solution can be greatly improved if static would be used. Only 10 times slower!
Empty array (CPU, Iterations): V2 - (5.12 ns, 139'957'070). Not empty array: V2 - (557 ns, 1'229'442)
Сan someone who voted this as the best practice explain why you did it? What criteria do you use?