Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test b@b regexp
(version: 0)
Comparing performance of:
classic vs better
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
classic
new RegExp("^([^./]+\\.)*slack\\.com/").test("sub1.sub2.slack.com/")
better
new RegExp("^(?:[^./]+\\.)*slack\\.com/").test("sub1.sub2.slack.com/")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
classic
better
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
classic
5808196.0 Ops/sec
better
5706433.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net, a website that allows users to create and run JavaScript microbenchmarks. **Benchmark Definition JSON** The provided JSON represents a benchmark definition with two test cases: "classic" and "better". Both test cases aim to measure the performance of regular expression (RegExp) matching in JavaScript. **What is tested?** In both test cases, we're testing the execution time of the `test()` method on a RegExp object. Specifically: * In "classic", the RegExp pattern is: `"^([^./]+\\\\.)*slack\\\\.com/"` * In "better", the RegExp pattern is: `"^(?:[^./]+\\\\.)*slack\\\\.com/"` **Options compared** These two test cases compare different approaches to regular expression matching: 1. **"classic"`**: This approach uses a more traditional, verbose syntax with `^` (start of string), `([^./]+\\.)` (capture one or more non-. characters and match exactly once), and `*` (zero or more occurrences). 2. **"better"`**: This approach uses a more concise syntax with `(?:)` (non-capturing group) around the non-`. character, and removes the `\.` (match a dot literally). **Pros and Cons** Here's a brief summary of the pros and cons of each approach: * **"classic"`**: + Pros: More readable, easier to understand for beginners. + Cons: Verbose syntax can lead to slower execution due to more characters being parsed. * **"better"`**: + Pros: More concise syntax can lead to faster execution since fewer characters need to be parsed. + Cons: Less readable and may require additional explanation or comments. **Library usage** Neither of the test cases uses any external libraries. The RegExp object is a built-in JavaScript API used for pattern matching. **Special JS feature/syntax** There's no special JavaScript feature or syntax being tested in this benchmark. **Other alternatives** If you were to modify these benchmarks, here are some alternative approaches you could consider: * Use `String.prototype.replace()` instead of `RegExp.test()`, as it might be faster for simple replacements. * Add more test cases with different patterns, such as those involving Unicode characters or non-ASCII characters. Keep in mind that the best approach depends on your specific use case and requirements. MeasureThat.net is an excellent tool for finding performance differences between various approaches to regular expression matching.
Related benchmarks:
Various regex testing patterns
new RegExp test
RegEx.test vs. String.includes vs. String.match vs String.search
startsWith vs test 3
Test "new RegExp(string)" vs "new RegExp(/regexp/)" vs "/regexp/"
Comments
Confirm delete:
Do you really want to delete benchmark?