Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test with/without regex
(version: 0)
Comparing performance of:
with regexp vs without regexp vs empty
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
with regexp
function getDisplayName(definitionName) { const bundleId = getBundleId(definitionName); return name.substring(name.lastIndexOf(':') + 1); } function getBundleId(definitionName) { const matches = definitionName.match(/(.+):/); return (matches && matches.pop()) || ''; } const res = getDisplayName('foo:bar');
without regexp
function getDisplayName(definitionName) { const bundleId = getBundleId(definitionName); return name.substring(name.lastIndexOf(':') + 1); } function getBundleId(definitionName) { const matches = definitionName.split(':'); return matches[0]|| ''; } const res = getDisplayName('foo:bar');
empty
function getDisplayName(definitionName) { const bundleId = getBundleId(definitionName); return bundleId; } function getBundleId(definitionName) { return definitionName; } const res = getDisplayName('foo:bar');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
with regexp
without regexp
empty
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
with regexp
2050688.9 Ops/sec
without regexp
2322037.8 Ops/sec
empty
80378472.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. The benchmark is comparing three different approaches to extract the bundle ID from a string in JavaScript: 1. **Using regular expressions (regex)**: This approach uses the `match()` method with a regex pattern to match the bundle ID part of the string. The pattern `/(.+):/` matches one or more characters (`.+`) followed by a colon (`:`). The `match()` method returns an array containing the matched value, which is then accessed using `matches.pop()`. 2. **Using string splitting**: This approach splits the input string into parts using the `split()` method with a separator of `:`, and then takes the first part as the bundle ID. 3. **Empty implementation**: This approach simply returns an empty string. Let's discuss the pros and cons of each approach: **Regex**: Pros: * Can match complex patterns * Flexible Cons: * Can be slow due to the overhead of compiling a regex pattern * May not work as expected if the input format changes **String splitting**: Pros: * Fast and efficient * Simple to implement Cons: * May not work correctly if the input string has multiple colon characters in a row * Limited flexibility for complex matching patterns **Empty implementation**: Pros: * Simple and lightweight * Guaranteed to return an empty string, eliminating the need for additional logic Cons: * Returns an empty string, which may or may not be what the user expects * May not meet performance expectations if used in a loop Now, let's talk about the libraries used in these benchmark cases. None of the test cases use any external libraries. As for special JavaScript features or syntax, the regex approach uses the `match()` and `pop()` methods, which are standard JavaScript methods. However, some browsers may have variations in their implementation (e.g., Safari has a slightly different `pop()` behavior). The benchmark results show that: * The "empty" implementation returns the fastest execution times across all platforms. * The "with regexp" implementation is slower than the "without regexp" approach and the "empty" implementation, but faster than the "without regexp" approach. * The "without regexp" implementation is the slowest of the three approaches. Other alternatives to consider: * Using a dedicated library for string manipulation or regex matching (e.g., `lodash.string`) * Implementing the `split()` method using a custom algorithm to optimize performance * Considering other string extraction techniques, such as using substring indexing or using a different separator character Keep in mind that these alternatives may have their own trade-offs and performance implications, so it's essential to evaluate them based on your specific use case.
Related benchmarks:
RegEx.test vs. String.includes larger
RegEx.exec vs regex.test qp
new RegExp test
RegEx.test vs RegEx.match when fails
Test "new RegExp(string)" vs "new RegExp(/regexp/)" vs "/regexp/"
Comments
Confirm delete:
Do you really want to delete benchmark?