I create a for loop to warm up the JVM and allow the compiler to start optimizing (This mimics a real world JVM and doing this we will get times 30% faster). start a timer, run my regular expression code 1000 times, end the timer. We do that four times and take the average. Which looks like this :
@Testfuntesting_again_test2(){valtimesToDo=1000LvalchannelName="cohhcarnage"vallongerParsingString="real world example of what you want to parse"// for loop to `warm up the JVM`for(iin4downTo1){varcount=timesToDovalstartTime=System.currentTimeMillis()while(--count>0){underTest.privateMessageParsing(longerParsingString,channelName)//privateMessageParsing() contains the matching actions we are bench marking. This is where you would substitute your own code.}valseconds=(System.currentTimeMillis()-startTime)/1000.0println("Alternation takes $seconds seconds")}}
my next blog post will be how I was able to improve my regular expressions(this involves reading a lot of technical documentation )
Conclusion
Thank you for taking the time out of your day to read this blog post of mine. If you have any questions or concerns please comment below or reach out to me on Twitter.
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)