Speed Optimization Tip: Only Use Regular Expression if Necessary
Making your automation scripts faster.
3 min readSep 28, 2024
Regular Expressions are a powerful and valuable pattern matching tool for strings. My father wrote an article on using Regular Expression (Regex) in automated test scripts.
In this short article, I will show you one aspect of using Regular Expression: it’s slow. When there are other ways you can accomplish pattern matching in a big loop, avoid using Regex.
The topic of this exercise is to analyse E2E test script files, recursively in a folder.
- test script files, end with
_spec.rb
or_test.rb
- page classes, end with
_page.rb
. - helpers, end with
_helper.rb
.
Also in a test script file, we will count the number of test cases (one test script may contain one or more test cases), which start with it
and end with do
.
Let me show you the results (in terms of speed) first.