Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
with/without regex
(version: 0)
Comparing performance of:
with regexp vs without
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
with regexp
function getDisplayName(definitionName, checkBundleId = true) { let displayName; const name = definitionName || ''; if (checkBundleId) { const bundleId = getBundleId(definitionName); displayName = name.substring(name.lastIndexOf(':') + 1); } else { displayName = name.substring(name.lastIndexOf(':') + 1); } return displayName; } function getBundleId(definitionName) { const name = definitionName || ''; const matches = name.match(/(.+):/); return (matches && matches.pop()) || ''; } const res = getDisplayName('foo:bar'); console.log(res);
without
function getDisplayName(definitionName, checkBundleId = true) { let displayName; const name = definitionName || ''; if (checkBundleId) { const bundleId = getBundleId(definitionName); displayName = name.substring(name.lastIndexOf(':') + 1); } else { displayName = name.substring(name.lastIndexOf(':') + 1); } return displayName; } function getBundleId(definitionName) { const name = definitionName || ''; const matches = name.split(':')[0]; return matches || ''; } const res = getDisplayName('foo:bar'); console.log(res);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
with regexp
without
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
242659.7 Ops/sec
without
243238.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided benchmark measures the performance difference between using regular expressions (regex) and not using them in JavaScript code. The benchmark is designed to test how much impact regex has on the execution speed of the code. **Benchmark Definition JSON Explanation** The benchmark definition json contains two properties: `Name` and `Description`. However, neither of these properties provide any meaningful information about what the benchmark measures or compares. The `Script Preparation Code` property should contain the JavaScript code that sets up the environment for the benchmark. In this case, it's empty, which is unusual. The `Html Preparation Code` property also doesn't seem to be relevant in this context. **Individual Test Cases** There are two test cases: 1. **"with regexp"`** This test case uses regular expressions (regex) in the JavaScript code. The regex pattern `/(.+):/` is used to extract a substring from a string. The `getBundleId` function splits the input string by colon (`:`) and returns the first part. Pros: * This approach allows for efficient extraction of specific parts from a string. * Regex can be more readable and concise than other parsing methods. Cons: * Using regex can be slower due to the overhead of compiling and executing regex patterns. * Regex patterns can become complex and harder to maintain. 2. **"without"`** This test case does not use regular expressions (regex) in the JavaScript code. Instead, it uses the `split` method to extract a substring from a string. Pros: * This approach is likely to be faster than using regex. * It's often simpler and more straightforward than regex parsing. Cons: * It may not be as efficient or scalable for complex parsing tasks. **Library** There doesn't seem to be any external library used in this benchmark. However, the `getBundleId` function uses a simple string splitting method (`split(':'')`) which is a built-in JavaScript function. **Special JS Feature/Syntax** None of the test cases use special JavaScript features or syntax that are not widely supported. **Other Alternatives** If you want to measure the performance impact of using regular expressions in JavaScript, you could also consider using: * `use-regex`: A polyfill for regex support in older browsers. * `regex-tester`: A library that provides a simple API for testing regex patterns. * ` benchmarking libraries` like Benchmark.js or js-benchmark which provide more features and flexibility for benchmarking. Keep in mind that the choice of alternative will depend on your specific use case and requirements.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match insensitive
RegEx.test vs. String.includes incasesensitive
RegEx.test vs. String.includes x 2
RegEx.test vs. String.includes vs. String.match chitza
RegEx.test vs. String.includes vs. String.match db
Comments
Confirm delete:
Do you really want to delete benchmark?