Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
split vs splitstring
(version: 0)
Comparing performance of:
splitstring vs split
Created:
one year ago
by:
Registered User
Jump to the latest result
Tests:
splitstring
function splitString(str = "", splitter = "", includeSplitter = false) { function getlast(string, len) { if (len > string.length) return -1; let s = ""; let o = string.length - 1 - len; for (let i = string.length - 1; i > o; i--) { s = string[i] + s; } return s; } if (typeof str !== "string" || typeof splitter !== "string") return str; if (!str.length) return [str]; let strPieces = []; if (!splitter.length) { for (let p = 0; p < str.length; p++) { strPieces.push(str[p]); } return [...strPieces]; } let splitterLen = splitter.length; let strCurPiece = ""; let tempStr = ""; for (let v = 0; v < str.length; v++) { strCurPiece += str[v]; if (strCurPiece.length < splitterLen) continue; //let lastchars = strCurPiece.last(splitterLen); let lastchars = getlast(strCurPiece, splitterLen); if (lastchars !== splitter) continue; if (includeSplitter) { strPieces.push(strCurPiece); strCurPiece = ""; continue; } let lenny = strCurPiece.length - splitterLen; for (let y = 0; y < lenny; y++) { tempStr += strCurPiece[y]; } strPieces.push(tempStr); strCurPiece = ""; tempStr = ""; } if (strCurPiece.length) strPieces.push(strCurPiece); return [...strPieces]; } splitString('dfasfasfaqqq','qqq')
split
'dfasfasfaqqq'.split('qqq')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
splitstring
split
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
splitstring
2937701.5 Ops/sec
split
34363596.0 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, compared, and their pros and cons. **Benchmark Definition** The benchmark is defined by two test cases: 1. `splitString` (individual function) 2. `'dfasfasfaqqq'.split('qqq')` (string method) Both tests aim to measure the performance of splitting a string into substrings using different approaches. **Options being compared** There are two main options being compared: A) **Individual function: `splitString`** B) **String method: `.split()`** Let's examine each option in detail. **A) Individual function: `splitString`** The `splitString` function takes three arguments: `str`, `splitter`, and `includeSplitter`. It splits the input string into substrings based on the specified splitter. The function returns an array of substring pieces. Pros: * Customizable (e.g., handling edge cases, specifying inclusion/exclusion of splitters) * Can be optimized for specific use cases Cons: * More complex implementation compared to the built-in `.split()` method * May require additional memory allocation for the `strPieces` array **B) String method: `.split()`** The `.split()` method is a built-in JavaScript function that splits a string into an array of substrings based on a specified separator (default is whitespace). Pros: * Simple and efficient implementation * Built-in, so no additional memory allocation required * Widely supported across browsers Cons: * Less customizable compared to the `splitString` function * May not handle edge cases as effectively (e.g., handling empty strings or separators) **Library/Functionality** The `splitString` function uses a custom implementation that includes an auxiliary function, `getlast()`, which extracts the last `n` characters from a string. This is necessary to efficiently compare substrings with the specified length. **Special JS feature/syntax** There are no special JavaScript features or syntax used in this benchmark. **Other alternatives** If you wanted to implement this benchmark using different approaches, here are some alternative options: 1. **Regular expressions**: Use regular expressions (e.g., `/q+/`) to split the string. 2. **Array.prototype.slice()**: Split the string by iterating over the array and applying `slice()` to each element. 3. **Other custom implementations**: Explore other algorithms for splitting strings, such as using a loop to iterate over the string and split it manually. Keep in mind that these alternatives may have different performance characteristics compared to the original implementation.
Related benchmarks:
Deep merge lodash 4.6.2 vs ramda vs deepmerge
Deep merge lodash vs ramda vs deepmerge vs native shallow merge
JSON.parse vs string.splitn
String concatenation vs array join Chrome 3
Template Literal vs Tagged Template Literal
Comments
Confirm delete:
Do you really want to delete benchmark?