Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegExp.exec 1k vs 10k vs 100k character string
(version: 0)
Testing exec (not found) times for different string lengths
Comparing performance of:
1k length string vs 10k length string vs 100k length string
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var regex = /Goodbye (World)/; var smallStr = ''; var medStr = ''; var largeStr = ''; for (var i = 0; i < 5000; i++) { if (i % 100 === 0) smallStr += 'Small World! ' + Math.floor(Math.random() * 8); if (i % 10 === 0) medStr += 'Medium World! ' + Math.floor(Math.random() * 6); largeStr += 'Large World! ' + Math.floor(Math.random() * 7); }
Tests:
1k length string
regex.exec(smallStr);
10k length string
regex.exec(medStr);
100k length string
regex.exec(largeStr);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
1k length string
10k length string
100k length string
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided benchmark measures the execution time of `RegExp.exec()` for strings of varying lengths (1k, 10k, and 100k characters). The benchmark creates three different strings: `smallStr`, `medStr`, and `largeStr`, which are populated with random text to simulate a real-world scenario. **Options Compared** The benchmark compares the execution time of `RegExp.exec()` for each string length: 1. **Small string (1k characters)** 2. **Medium string (10k characters)** 3. **Large string (100k characters)** **Pros and Cons of Different Approaches:** * Using a large number of random strings to create the test data can help ensure that the results are representative of real-world usage patterns. + Pros: More realistic testing, better handling of edge cases. + Cons: Increased computational time, potential for slower benchmark results. * Using a fixed-length string with random text can provide a more controlled environment for testing. + Pros: Faster benchmark results, easier to analyze and compare results. + Cons: May not accurately represent real-world usage patterns. **Library Used** In this benchmark, the `RegExp` object is used. The `RegExp` object is a built-in JavaScript library that provides regular expression matching functions, including `exec()`. **Special JS Feature or Syntax** The benchmark uses the `Math.floor(Math.random() * 8)` syntax to generate random numbers within a specific range for the small string. This syntax is not particularly noteworthy, as it's a common way to generate random integers in JavaScript. **Other Considerations:** * The benchmark does not account for any potential errors or exceptions that may occur during execution. * There are no input validation checks for the `RegExp` object or its methods. * The benchmark assumes that the `RegExp` object is initialized with a compiled regular expression using the `/Goodbye (World)/` pattern. **Alternatives:** If you were to recreate this benchmark, consider the following alternatives: 1. **Use a more realistic random string generation method**, such as generating strings from a character set or using a random text generator library. 2. **Add input validation checks** for the `RegExp` object and its methods to ensure robustness and reliability. 3. **Consider adding error handling** to account for potential exceptions during execution. 4. **Use a more efficient string creation method**, such as using an array of characters or a string builder, to reduce computational overhead. Keep in mind that these alternatives may affect the accuracy or efficiency of the benchmark results.
Related benchmarks:
JS Regex vs .startsWith vs .indexOf
JS Regex vs .startsWith vs .indexOf simpler
JS Regex vs .startsWith vs .indexOf Jan
JS Regex vs .startsWith
JS Regex vs .startsWith vs .indexOf but with lowercase when checking index
Comments
Confirm delete:
Do you really want to delete benchmark?