Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test benchmark 123
(version: 0)
Comparing performance of:
RegEx.test vs String.includes
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = "P400 Dynamic HSE 4dr SUV AWD w/Zadar Grey Premium Metallic Paint (3.0L 6cyl Twincharger gas/electric mild hybrid 8A)"; var regex = /^[\w\s\-.'"()#+!]+/;
Tests:
RegEx.test
regex.test(string);
String.includes
function mimicRegex(string) { const allowedChars = new Set(`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\-.\'"()#+! `); let index = 0; for (let char of str) { if (!allowedChars.has(char)) { return str.substring(0, index); } index++; } return str; // Return the entire string if it matches the regex }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
RegEx.test
String.includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
RegEx.test
10124943.0 Ops/sec
String.includes
194543904.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided benchmark definition and test cases are used to compare the performance of two different approaches: using a regular expression (RegEx) and creating a custom string filtering function. **Benchmark Definition and Preparation Code** The benchmark definition consists of two test cases: 1. `RegEx.test`: Tests the performance of the `test()` method on a given string. 2. `String.includes`: Tests the performance of a custom string filtering function using the `includes()` method. The script preparation code provides a sample string: `"P400 Dynamic HSE 4dr SUV AWD w/Zadar Grey Premium Metallic Paint (3.0L 6cyl Twincharger gas/electric mild hybrid 8A)"`. The HTML preparation code is empty, indicating that no HTML-specific benchmarking is required. **Comparison of Options** Two options are compared: 1. **RegEx.test**: Uses the built-in `test()` method to search for a pattern in the string. 2. **String.includes**: Creates a custom function using a `Set` to filter out disallowed characters from the input string. **Pros and Cons of Each Approach** **RegEx.test:** Pros: * Easy to implement and understand * Built-in JavaScript method, which means it's well-supported across different browsers Cons: * May be slower than the custom implementation due to overheads in regular expression engine * Limited control over the filtering process **String.includes:** Pros: * Allows for fine-grained control over the filtering process * Can be optimized for performance using techniques like caching and memoization Cons: * More complex implementation compared to RegEx.test * May require additional setup and maintenance, especially if the filter logic changes frequently. **Library Used (if any)** None of the provided test cases use a dedicated library. However, if you were to create more complex benchmarking scenarios, libraries like `regex-escape` or `sanitize-html` might be useful for handling regular expressions or HTML sanitization, respectively. **Special JavaScript Feature/ Syntax** The custom implementation in `String.includes` uses a `Set` data structure and the `includes()` method. The use of `Set` is not specific to any particular feature, but it's an efficient way to store unique values. However, this test case does not require any special JavaScript features or syntax. **Alternatives** If you wanted to create more complex benchmarking scenarios using MeasureThat.net, some alternatives might include: * Using different types of data structures (e.g., arrays, objects) and data sources (e.g., JSON, CSV) * Introducing additional complexities like asynchronous programming, callbacks, or promises * Experimenting with browser-specific features like WebAssembly, Web Workers, or service workers Keep in mind that the performance comparisons on MeasureThat.net are typically focused on vanilla JavaScript implementations, so exploring more advanced scenarios might require modifications to the benchmark definition and test cases.
Related benchmarks:
test test
정규식 vs includes
RegEx.test vs. String.includes vs. String.match 1
RegEx.test vs. String.includes x 2
Comments
Confirm delete:
Do you really want to delete benchmark?