[libcxx-commits] [PATCH] D61878: Use is_permutation when comparing containers

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 14 18:13:01 PDT 2019


zoecarver added a comment.

@ldionne I can add a test that asserts one function takes less time than another, but it might fail if tests are run in parallel or if the computer's resources are being used more heavily while one of the tests is being run. I think it is unlikely that such circumstances arise, but it is possible.

While it is harder for me to show //why// `is_permutation` is faster, it follows logic that it would be at least as fast. Essentially, the old function looped through every element of the set. For each element, it would find all elements containing the same value as that element. Then, it would check `is_permutation` for that set of elements (who were required to both be the equal values and have the same size!). Assuming `is_permutation` works as specified in the standard, it does the same thing. However, it cuts out unnecessary calls to `is_permutation`, does not have to loop through every element, and has other optimizations. In other words, the standard specifies that `is_permutation` must have a maximum of O(n^2) complexity, the current (old) function is more complex than that, therefore, even if `is_permutation` is updated, it should still be faster.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61878/new/

https://reviews.llvm.org/D61878





More information about the libcxx-commits mailing list