I’m using Scala to measure performance of regex engine of java. The regexp below executes in around 3 seconds but yet I’m not able to measure it using System.currentTimeMillis. (the last expression returns 0)
scala> val b = System.currentTimeMillis; val v = new Regex("(x+)+y").findAllIn("x"*25); b-System.currentTimeMillis
b: Long = 1330787275629
v: scala.util.matching.Regex.MatchIterator = empty iterator
res18: Long = 0
Do you now why the last returned value is 0, and not the amount of ms that scala spend on executing the regexp?
The unexplained duration comes from the REPL calling
toStringon the iterator returned fromfindAllIn. This in turn callsRegex.MatchIterator#hasNext, which triggers the search.