Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array from vs string split (modified with long strings)
(version: 0)
Comparing performance of:
Array.from vs string split
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var s1 = "foo".repeat(1000000); var s2 = "foo 12312".repeat(1000000);
Tests:
Array.from
let n1 = Array.from(s1); let n2 = Array.from(s2);
string split
let n1 = s1.split(''); let n2 = s2.split('');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array.from
string 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/132.0.0.0 YaBrowser/25.2.0.0 Safari/537.36
Browser/OS:
Yandex Browser 25 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.from
13.4 Ops/sec
string split
34.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and explain what's being tested. **Benchmark Overview** The test case measures the performance of two JavaScript functions: `Array.from()` and string splitting using the `.split()` method. Both tests create large arrays from strings by repeating a pattern ("foo" or "foo 12312") millions of times. **Options Compared** 1. **`Array.from()`**: This function takes an iterable (in this case, a string) as an argument and returns a new array with the same elements. 2. **`.split('')```**: This method splits a string into an array of substrings using a delimiter ("") that is always empty, effectively splitting the string into individual characters. **Pros and Cons** * `Array.from()`: + Pros: Creates a new array with the original data's elements, allowing for more flexible indexing and manipulation. It also provides better performance than `.split()` for large arrays. + Cons: Can be slower for very small arrays or when the input is not an iterable. * `.split('')```**: Pros: + Fast for small arrays or strings with a short delimiter. + Can be used to split strings into individual characters, which might be necessary in certain situations (e.g., processing HTML). - Cons: Creates a new array of individual characters, which can lead to unnecessary memory allocation and slower performance for large arrays. It also returns an array of all characters in the original string, including any whitespace or punctuation. **Library** The `Array.from()` method is part of the ECMAScript standard since ES6 (2015) and is implemented in most modern JavaScript engines. The `.split('')``` method is also a built-in method in most browsers and Node.js environments. **Special JS Feature/Syntax** There are no special JavaScript features or syntaxes being used here, but I'll note that the use of template literals (`var s1 = "foo".repeat(1000000);`) allows for a more concise way to create large strings. Additionally, the `let` keyword is used with block scope, which is a feature introduced in ECMAScript 2015 (ES6). **Other Alternatives** For testing similar performance characteristics, you could consider benchmarks that compare: * Array creation using `Array.from()` vs. traditional array construction methods (e.g., `new Array(...)`). * String splitting using different delimiters or regular expressions. * Other array or string manipulation methods (e.g., `.map()`, `.filter()`, `.reduce()`). Keep in mind that the specific benchmark details and options will depend on your use case and performance requirements.
Related benchmarks:
Array.from(string) vs string.split("")
Array split vs string substring for dates
Array split vs string substring ISO String
Array split vs string substring22
Comments
Confirm delete:
Do you really want to delete benchmark?