<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
var a = [[1,23,5,6,7],[1,2,3,4],[6,4,87]]
R.flatten(a)
[].concat.apply([], a)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
ramda | |
native |
Test name | Executions per second |
---|---|
ramda | 1395464.9 Ops/sec |
native | 2610001.5 Ops/sec |
I'd be happy to explain what's tested in this benchmark.
Benchmark Definition
The benchmark is defined by a JSON object that contains the following information:
Name
: The name of the benchmark, which is "test ramda flatten".Description
: An empty string, indicating that there is no description for this benchmark.Script Preparation Code
and Html Preparation Code
: These two sections contain code that is executed before running the benchmark. The first one defines a JavaScript array a
using nested arrays, which will be used in both test cases. The second section includes an HTML script tag to load the Ramda library (version 0.25.0) for use in the benchmark.Test Cases
There are two individual test cases:
**: This test case uses the
R.flattenfunction from the Ramda library to flatten the nested array
a`.**: This test case uses the native JavaScript
concat.applymethod to flatten the same array
a`.Options Compared
In this benchmark, two options are being compared:
R.flatten
) to perform the flattening.concat.apply
) for the same purpose.Pros and Cons of Each Approach
Ramda Library (R.flatten)
Pros:
Cons:
Native JavaScript (concat.apply)
Pros:
Cons:
Other Considerations
It's worth noting that this benchmark only compares the two test cases on a specific browser and device platform. Results may vary when running the benchmark on different environments.
If you want to compare other approaches, such as:
Array.prototype.flat()
(a newer JavaScript method)You would need to modify the Script Preparation Code
and/or Html Preparation Code
sections of the benchmark definition accordingly.
Additionally, if you want to test special JavaScript features or syntax, such as async/await, generators, or Promises, you would need to modify the test cases and script preparation code to incorporate those features.