I have a very simple regex-based parser. Parser extracts some specific key-value pairs from plain text. It takes about 10ms per plain text document. Average document length is about 700 bytes, biggest document found is ~2kb.
Everything work fine until unit tests run.
Most of tests run fast (from build to build graph from build server):
Some of tests occasionally run fast:
But some of them stuck for a minutes:
The only difference between unit tests is document's text and object to be compared to result. And order in which they run.
When I run this code manually (e.g. in console app), it runs extremely fast compared to unit test (10ms vs 2.5min).
Profiling test runner exposed that most of time consumed by regex - Regex.Scan method. Looking a bit deeper I found following:
JIT compilation? Seems like RegexOptions.Compiled option affected. When this option was removed, tests run fast.
So my questing is why regex compilation takes so much time when run in test runner (either on build server or locally)? And why it always run fast otherwise (console app with exactly same code never took more then 2 seconds from start to end)?
Regexes are very simple, e.g.: (?:^\s*(?<property>Some|option(?:s and names)?|of|keys)\s*[\s:=-](?:(?!\r?\n)\s)*(?<value>(?:(?!\r?\n).)*)(?:(?!\r?\n)\s)*(?:\r?\n|$))
Unit tests are implemented with xUnit 2.0, .NET 4.5, AnyCPU, Release build, x64 machine.
Aucun commentaire:
Enregistrer un commentaire