-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hasKey performance issue #172
Comments
Same problem with |
I just had a look at implementation of It would certainly be possible to create an optimised matcher especially for the case of matching an expected literal key inside a map, or a literal item inside a collection. It would be a slight amount of extra complexity for the better performance. Out of interest, is the performance of this matcher causing any problems for your code? |
Not as of yet, I have to admit. However, I have written a library that relies heavily on Hamcrest that validates method preconditions and I can foresee that some methods accepting maps or collections may be inside heavily used loops. Normally, such an algorithm would operate in linear time when using hash maps or hash sets, but with the current implementation of these matchers such an algorithm would perform in |
Understood. Are you able to submit a PR? |
Sure. I can probably have it up Friday or Monday evening. |
@nibsi , it looks like I'm bitten with the same issue. Have you had a chance to optimize |
@tumbarumba @vlsi sorry guys, I completely got sidetracked. Thanks for the reminder. I'm busy over the weekend, but I'll definitely hop to it the coming week. Stay tuned. |
…taining.hasEntry(), which use the map's own containsKey(K key) method to avoid an O(n) worst-case linear search for every match. This implements the change proposed in issue hamcrest#172
I know this issue is old, but I went ahead and prepared a Pull Request that implements this proposed optimization. @tumbarumba and @nibsi, would you mind looking at this change if you have some time, please? |
Why
IsMapContaining.hasKey(K key)
is iterating over whole map, instead of callingMap.containsKey
? Latter is much faster!The text was updated successfully, but these errors were encountered: