Ad
  • Default User Avatar

    This solution is very slow, look at the rock4259 solution, it is an order of magnitude faster. 572 ns and 35 ns respectively.

  • Default User Avatar

    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? :-)

  • Default User Avatar

    In my opinion, this is the most effective solution.

  • Default User Avatar

    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

  • Default User Avatar

    "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

  • Default User Avatar

    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)

  • Default User Avatar

    Сan someone who voted this as the best practice explain why you did it? What criteria do you use?