Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Regex evaluation
(version: 1)
Comparing performance of:
Regex vs Substring vs Full Regex
Created:
8 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var matchDirective = /webapp-v-([a-z-]+)(?::([a-zA-Z_.-]+))?/, fullDirective = /webapp-v-([a-z-]+)(?::([a-zA-Z_-]+)(?:\.([a-zA-Z_-]+))?)?/, attrName = "webapp-v-bind:class.ifdefined";
Tests:
Regex
var directivematch = matchDirective.exec(attrName), directivename = directivematch[1], directivopts = directivematch[2], pos = directivopts.indexOf("."), attrname = directivopts.substring(0, pos), buildIn = directivopts.substring(pos+1);
Substring
var directivematch = matchDirective.exec(attrName), pos = attrName.indexOf(":"), directivename = attrName.substring(0, pos), directivopts = attrName.substring(pos+1), posbuild = directivopts.indexOf("."), attrname = directivopts.substring(0, posbuild), buildIn = directivopts.substring(posbuild+1);
Full Regex
var directivematch = fullDirective.exec(attrName), directivename = directivematch[1], attrname = directivematch[2], buildIn = directivematch[3];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Regex
Substring
Full Regex
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Regex
3481533.5 Ops/sec
Substring
1689711.0 Ops/sec
Full Regex
3140717.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **What is being tested?** The provided benchmark is testing three different approaches to extract specific information from a string, specifically: 1. **Regex evaluation**: Using regular expressions (regex) to extract the `webapp-v-bind:class.ifdefined` attribute from an input string. 2. **Substring search**: Searching for a substring within the input string to extract the same attribute. 3. **Full regex with multiple captures**: Using a more complex regex pattern to capture all possible variations of the `webapp-v-bind:class.ifdefined` attribute. **Options compared** The benchmark is comparing the performance of three different approaches: 1. **Regex evaluation**: Using the built-in `exec()` method with a regex pattern. 2. **Substring search**: Searching for a specific substring within the input string using the `indexOf()` and `substring()` methods. 3. **Full regex with multiple captures**: Using a more complex regex pattern to capture all possible variations of the attribute. **Pros and cons of each approach** 1. **Regex evaluation**: * Pros: Efficient, concise, and effective for specific patterns like this one. * Cons: Can be slow if the regex pattern is overly complex or matches too many strings. 2. **Substring search**: * Pros: Simple, fast, and suitable for simple searches like this one. * Cons: May not work well with more complex patterns or variable-length substrings. 3. **Full regex with multiple captures**: * Pros: More flexible and can handle complex patterns, but may be slower due to the increased complexity. * Cons: Can be harder to read, maintain, and debug, especially for less experienced developers. **Library used** None explicitly mentioned in the benchmark definition or test cases. However, it's likely that the regex pattern is using built-in JavaScript methods like `exec()`, `indexOf()`, and `substring()` which are part of the standard library. **Special JS feature or syntax** The benchmark uses a special syntax for regex patterns, specifically: * The `/regex-pattern/` syntax for defining regex patterns. * The `\g<capture-index>` syntax for referencing capture groups in the regex pattern. These features are part of the JavaScript language and are used to define complex regex patterns that can handle multiple captures. **Alternatives** Other alternatives to these approaches could include: 1. **Using a dedicated regex library**: Depending on the complexity and frequency of regex usage, using a dedicated library like `regex-test` or `regex-js` might provide better performance and features. 2. **Using alternative substring search methods**: Other methods like `String.prototype.indexOf()` or `String.prototype.lastIndexOf()` might be faster for simple searches. 3. **Using more advanced parsing techniques**: Techniques like parsing the input string as an abstract syntax tree (AST) could potentially provide better performance, but may add complexity and overhead. Keep in mind that the best approach depends on the specific use case, frequency of usage, and personal preference.
Related benchmarks:
String.match vs. RegEx.test
String vs regex
Various regex testing patterns
pippoepluto
Regex type checking comparison
Comments
Confirm delete:
Do you really want to delete benchmark?