Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
fromCharCode apply vs spread
(version: 0)
Comparing performance of:
apply vs spread
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
data = new Uint8Array([239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 32, 47, 32, 84, 104, 101, 32, 66, 101, 103, 117, 105, 108, 101, 100, 32, 40, 49, 57, 55, 49, 41, 32, 66, 68, 82, 105, 112]);
Tests:
apply
let result = String.fromCharCode.apply(0, data);
spread
let result = String.fromCharCode(...data);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
apply
spread
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/99.0.4844.84 Safari/537.36
Browser/OS:
Chrome 99 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
apply
1944735.1 Ops/sec
spread
404722.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll explain the benchmarking test for `fromCharCode apply vs spread` in detail. **Benchmark Description** The benchmark measures the performance difference between two ways to create an array of characters using the `String.fromCharCode()` method: `apply` and `spread`. **What is being tested?** * The `String.fromCharCode()` method takes a sequence of Unicode code points as arguments and returns a string created by combining the corresponding characters. * In this benchmark, we're comparing the performance of two approaches: 1. Using `apply()`: `String.fromCharCode.apply(0, data);` 2. Using the spread operator (`...`): `String.fromCharCode(...data);` **Options compared** The benchmark is comparing the following options: * **Using `apply()`**: This method calls a function with the provided arguments as an array. * **Using the spread operator (`...`)**: This method creates an array from the provided sequence of values. **Pros and Cons of each approach:** * **Using `apply()`**: + Pros: - Can be more concise when working with specific functions that expect an array as an argument. - Less overhead since it doesn't create a new array. + Cons: - Requires the `apply()` method to be called explicitly, which can make the code less readable. - Not supported in all browsers (e.g., older versions of Internet Explorer). * **Using the spread operator (`...`)**: + Pros: - More concise and expressive than using `apply()`. - Works in all modern browsers. + Cons: - Creates a new array, which can have overhead compared to using `apply()`. **Library usage** In this benchmark, no libraries are used beyond the built-in JavaScript methods. **Special JS feature or syntax** The spread operator (`...`) is a relatively recent addition to JavaScript (introduced in ECMAScript 2015). It allows for more concise array creation and has become a popular choice in modern JavaScript development. **Benchmark preparation code** The benchmark prepares an array `data` containing the Unicode code points to be used with `String.fromCharCode()`. The array is created using two different methods: `apply()` and `spread`. **Test cases** There are two test cases: * **"apply"`**: This test case uses `String.fromCharCode.apply(0, data);`. * **"spread"`**: This test case uses `String.fromCharCode(...data);`. These test cases measure the performance of each approach when used with `String.fromCharCode()`. **Latest benchmark result** The latest benchmark results show that: * Using `apply()` outperforms using the spread operator (`...`) on this specific benchmark. * Chrome 98 browser shows the best performance for both approaches.
Related benchmarks:
slice vs subarray vs set custom
compression libraries comparison smol2
tmpcanvas
tmpcanvas2
Comments
Confirm delete:
Do you really want to delete benchmark?