Skip to content

Instantly share code, notes, and snippets.

@jamie-mcilroy
Last active November 27, 2020 16:18
Show Gist options
  • Save jamie-mcilroy/d557f76c6d0290ce9efcf15c9508e94a to your computer and use it in GitHub Desktop.
Save jamie-mcilroy/d557f76c6d0290ce9efcf15c9508e94a to your computer and use it in GitHub Desktop.
test regex for speed
@Test
void testTeamRegex() {
String expectedStringToFind ="{status: Running, ballpos: -0.0375, distance: 1.143484}";
String sfeed = "efewfewfew{status: Running, ballpos: -0.0375, distance: 1.143484}dweewdew";
long startTime = System.currentTimeMillis();
Pattern localPattern = Pattern.compile("\\{.*\\}" );
Matcher matcher = localPattern.matcher(sfeed);
matcher.toMatchResult();
assertTrue(matcher.find());
assertEquals(expectedStringToFind, matcher.group());
long endTime = System.currentTimeMillis();
long totalTime = endTime-startTime;
assertTrue(totalTime<10);
System.out.println("testTeamRegex Time to run (in ms): " + totalTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment