Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Regexp vs split cookie
(version: 0)
Comparing performance of:
Regexp vs Split
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var cookie = 'intercom-id-mrtzdw2q=c2be8491-1730-4343-b16e-1c708643318e; token=eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiIsImtpZCI6IjhjMTgyMTY1YWNmN2U3Yjg3NzkwNzcxNWFmZWRiNzhmIn0.e30.McvbBVzvGzsawYch7ToCgtCrUicIQZ3_wNBV93fVBMm90JTldSpzdDgXd0eY7au1AxQst08mH-7FVy4C8wr4EQ; intercom-session=acj; intercom-session-mq='
Tests:
Regexp
const TOKEN_REGEXP = /token=(\S+)/ const [, token] = TOKEN_REGEXP.exec(cookie) console.log(token)
Split
const token = cookie?.split('token=')[1] ? cookie.split('token=')[1].split(';')[0] : undefined console.log(token)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Regexp
Split
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 139 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Regexp
70146.9 Ops/sec
Split
73320.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
The test on MeasureThat.net is designed to compare the performance of two approaches for extracting a token from a cookie string in JavaScript: using regular expressions (Regexp) versus splitting the string. **Options compared:** 1. **Regular Expressions (Regexp):** * Using a RegExp object with a pattern to match the token. * Extracting the matched token using `exec()` and destructuring it into an array (`const [, token] = TOKEN_REGEXP.exec(cookie)`). 2. **Split method:** * Slicing the cookie string at the 'token=' substring using `[1]`. * Extracting the token from the resulting slice using another slicing operation (`split(';')[0]`). **Pros and Cons of each approach:** **Regexp:** Pros: * Can be more flexible for complex pattern matching. * Might be faster due to the optimized implementation in JavaScript engines. Cons: * Can be slower if the pattern is complex or the string is very large, as it may trigger additional checks. * May require more code and setup for error handling. **Split method:** Pros: * Often faster and more efficient, as slicing operations are implemented in native code. * Easier to read and write, with less complexity. Cons: * May be limited by the specific split string used ('token='). * Can lead to errors if the token is not correctly separated from other data. **Other considerations:** * The `cookie` string contains additional data (e.g., intercom-session and intercom-session-mq) that may affect performance. The benchmark assumes that these parts are not relevant for extracting the token. * The `Token_REGEXP` pattern in Regexp test uses a raw string literal (`/token=(\\S+)/`) to avoid issues with backslashes and escape sequences. **Library usage:** None of the code snippets use any external libraries or frameworks beyond JavaScript's built-in functionality. **Special JS feature or syntax:** The Regexp test uses an arrow function syntax (e.g., `const [, token] = TOKEN_REGEXP.exec(cookie)`) to simplify the execution. This is a modern JavaScript feature introduced in ECMAScript 2015 (ES6).
Related benchmarks:
Ga cookie grabber . 3
test split vs match regex
Token from cookie
RegEx vs Reduce
Comments
Confirm delete:
Do you really want to delete benchmark?