Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sentexts
(version: 0)
Comparing performance of:
regex vs split
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
regex
const url = 'a\nsdassssss\nsssssas sdfgsdfgdfg\n https://gift.truemoney.com/campaign/?v=70ad8ee7c22c4cecb09265969a8d9b5622mddddddddddddddddddddddddsd fgsd\n fgsdf gsdfg'; const regex = /truemoney.*\?v=([a-zA-Z0-9]{35})/; const match = url.match(regex); if (match) { console.log(match[1]) }
split
const url = 'a\nsdassssss\nsssssas sdfgsdfgdfg\n https://gift.truemoney.com/campaign/?v=70ad8ee7c22c4cecb09265969a8d9b5622mddddddddddddddddddddddddsd fgsd\n fgsdf gsdfg'; if(url.includes("truemoney.com")){ console.log(url.trim()?.split("?v=")[1]?.substring(0, 35).trim()) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
regex
split
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
regex
115574.9 Ops/sec
split
124304.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided benchmark definition consists of two test cases: "regex" and "split". **Test Cases** 1. **Regex Test Case** The first test case uses the `regex` keyword in the benchmark definition. ```javascript const url = 'a\\nsdassssss\\nsssssas sdfgsdfgdfg\\n https://gift.truemoney.com/campaign/?v=70ad8ee7c22c4cecb09265969a8d9b5622mddddddddddddddddddddddddsd fgsd\\n fgsdf gsdfg'; const regex = /truemoney.*\\?v=([a-zA-Z0-9]{35})/; const match = url.match(regex); if (match) { console.log(match[1]); } ``` This test case is designed to measure the performance of a regular expression search in JavaScript. The regular expression `/truemoney.*\\?v=([a-zA-Z0-9]{35})/` searches for the pattern "truemoney" followed by any characters (`*`) and then captures the next 35 characters that come after `?v=`. **Pros and Cons of Regex Approach** The regex approach has some pros: * It can be more efficient than other string manipulation methods, as it leverages the browser's built-in regular expression engine. * It can handle complex patterns and searches. However, it also has some cons: * It can be slower for simple searches or if the input strings are not optimized for regex. * The performance depends on the complexity of the pattern and the input data. 2. **Split Test Case** The second test case uses the `split` keyword in the benchmark definition. ```javascript const url = 'a\\nsdassssss\\nsssssas sdfgsdfgdfg\\n https://gift.truemoney.com/campaign/?v=70ad8ee7c22c4cecb09265969a8d9b5622mddddddddddddddddddddddddsd fgsd\\n fgsdf gsdfg'; if(url.includes("truemoney.com")){ console.log(url.trim()?.split("?v=")[1]?.substring(0, 35).trim()) } ``` This test case is designed to measure the performance of string manipulation using the `includes` method and the `split` function. **Pros and Cons of Split Approach** The split approach has some pros: * It can be faster than the regex approach for simple searches or if the input strings are not optimized for regex. * The performance depends on the complexity of the operation and the input data. However, it also has some cons: * It can be slower for complex searches or if the input data is large. * The performance may vary depending on the browser's implementation of the `includes` method and the `split` function. **Library Used: None** Neither of the test cases uses any libraries. They rely solely on built-in JavaScript functions and features. **Special JS Feature/Syntax: None** There are no special JavaScript features or syntax used in these benchmark definitions. **Alternative Approaches** Other approaches to measure string manipulation performance could include: * Using a `substr` function instead of substring. * Using a `indexOf` method instead of includes. * Comparing the performance of different string concatenation methods (e.g., using template literals, string.join(), etc.). * Measuring the performance of different sorting algorithms for arrays of strings. These alternative approaches can help provide additional context and insights into the performance characteristics of different JavaScript functions and features.
Related benchmarks:
test4534553543534543543
test autocomplete computed items
flat vs concat (simplest) vs spread with object
spread operator VS delete
RegEx.test vs. String.includes vs. String.match for lists
Comments
Confirm delete:
Do you really want to delete benchmark?