harrisric commented on code in PR #367: URL: https://github.com/apache/maven-enforcer/pull/367#discussion_r2133706285
########## enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/utils/TestArtifactMatcher.java: ########## @@ -125,6 +125,37 @@ void testMatch() { executeMatch(matcher, "groupId", "anotherArtifact", "1.1", "", "", false); } + @Test + void testMatcherPerformance() { + patterns.add("groupId:artifactId:1.0"); + patterns.add("*:anotherArtifact"); + + ignorePatterns.add("badGroup:*:*:test"); + ignorePatterns.add("*:anotherArtifact:1.1"); + + ArtifactMatcher matcher = new ArtifactMatcher(patterns, ignorePatterns); + + long startTime = System.nanoTime(); + Artifact artifactGood1 = createMockArtifact("groupId", "artifactId", "1.0", "", "", ""); + Artifact artifactGood2 = createMockArtifact("groupId", "anotherArtifact", "1.0", "", "", ""); + Artifact artifactBad1 = createMockArtifact("badGroup", "artifactId", "1.0", "", "test", ""); + Artifact artifactGood3 = createMockArtifact("badGroup", "anotherArtifact", "1.0", "", "", ""); + Artifact artifactBad2 = createMockArtifact("groupId", "anotherArtifact", "1.1", "", "", ""); + for (int i = 0; i < 10_000; i++) { + assertEquals(true, matcher.match(artifactGood1)); + assertEquals(true, matcher.match(artifactGood2)); + assertEquals(false, matcher.match(artifactBad1)); + assertEquals(true, matcher.match(artifactGood3)); + assertEquals(false, matcher.match(artifactBad2)); + } + long timeTakenNs = System.nanoTime() - startTime; + assertTrue( + timeTakenNs < 200_000_000, + String.format( + "Time taken for repeated tests should be less than 200ms, but was: %dms", + timeTakenNs / 1_000_000)); + } Review Comment: Seems to have been exactly on the value that was allowed so would want to give it at least 10% margin for variation. The difference from the previous version was at least 50% faster. Happy to take any suggestions on this as to whether this test is a good idea or an alternative approach. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org