Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Regex lookarounds
(version: 0)
Comparing performance of:
groups vs lookahead vs lookbehind and lookahead
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var str=`È da tempo che, in relazione allo sviluppo delle nuove tecnologie – da un ,lato . 23,45 ciao a`
Tests:
groups
return str.replace(/([.,:;!?])([a-zA-Z])/gm, '$1 $2')
lookahead
return str.replace(/([.,:;!?])(?=[a-zA-Z])/gm, '$1 ')
lookbehind and lookahead
return str.replace(/(?<=[.,:;!?])(?=[a-zA-Z])/gm, ' ')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
groups
lookahead
lookbehind and lookahead
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark JSON and explain what's being tested. **Benchmark Overview** The benchmark is focused on measuring the performance of JavaScript regular expression (regex) lookarounds, which are used to match patterns without consuming characters from the input string. **Benchmark Definition JSON** The `Script Preparation Code` section defines a test string: `str = 'È da tempo che, in relazione allo sviluppo delle nuove tecnologie – da un ,lato . 23,45\r\n\r\nciao a'`. This string contains various punctuation marks and letters. **Individual Test Cases** There are three test cases: 1. **groups**: This test case uses the `replace` method with a capturing group (`([a-zA-Z])`) to match any letter after each punctuation mark (`([.,:;!?])([a-zA-Z])/gm`). The expected result is that all punctuation marks are replaced by their corresponding letter. 2. **lookahead**: Similar to the previous test case, but without the capturing group. Instead, it uses a lookahead assertion (`(?=[a-zA-Z]`) to match any letter after each punctuation mark, replacing the punctuation mark with a space only when followed by a letter. 3. **lookbehind and lookahead**: This test case combines both lookarounds. It uses a negative lookbehind assertion (`(?<=[.,:;!?])`) to match any punctuation mark before a letter, but still replaces the punctuation mark with a space. **Library Usage** None of the test cases use external libraries. The `replace` method is a built-in JavaScript function. **Special JS Features/Syntax** The benchmark uses regular expression lookarounds (positive and negative lookahead assertions), which are a standard feature in JavaScript regex engines. There's no specific syntax or special feature being tested here, just basic regex operations. **Other Considerations** * The `gm` flags used in the test cases enable global matching (`g`) and multi-line mode (`m`). * The `\r\n\r\n` characters in the input string may cause issues with some browsers or environments. It's likely that the benchmark is testing the behavior of these lookarounds in a specific scenario. * Since there are three test cases, the benchmark aims to measure the performance difference between each approach. **Alternatives** Some alternative approaches to measuring regex performance could include: 1. Measuring the execution time of a single regex pattern with different flags (e.g., `g`, `m`, etc.) and input strings. 2. Using a more comprehensive benchmarking framework that tests multiple regex patterns, data types, and browsers. 3. Comparing the performance of JavaScript engines (e.g., V8, SpiderMonkey) by running benchmarks on specific use cases. However, MeasureThat.net's approach allows for a simple and focused test case to measure the performance difference between lookarounds in different scenarios.
Related benchmarks:
Unnecessary non-capturing groups
Remove diacritics from string
String.replace(RegEx) vs String.replaceAll(String)
replaceAll vs regex replace pt2
replaceAll vs regex replace pt3
Comments
Confirm delete:
Do you really want to delete benchmark?