Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array of objects property extraction
(version: 0)
Comparing performance of:
ramdajs collectBy vs map vs ramdajs project
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
Script Preparation code:
var arr = [...Array(2000).fill({ test: 'val'})];
Tests:
ramdajs collectBy
R.collectBy(R.prop('test'), arr)[0];
map
arr.map(({ test }) => test);
ramdajs project
const getTest = R.project(['test']) const result = getTest(arr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
ramdajs collectBy
map
ramdajs project
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
ramdajs collectBy
0.0 Ops/sec
map
91597.2 Ops/sec
ramdajs project
15533.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark definition and test cases to explain what's being tested, compare different approaches, and discuss pros and cons. **Overview** The provided benchmark measures the performance of extracting an object property from an array of objects using three different methods: `map`, `collectBy` (from the Ramda library), and a custom implementation (`project`). **Test Cases** There are three test cases: 1. **"ramdajs collectBy"`: This test case uses the `collectBy` function from the Ramda library to extract the value of the `"test"` property from each object in the array. 2. **"map"`: This test case uses the built-in `map` function to achieve the same result as `collectBy`. 3. **"ramdajs project"`: This test case uses the `project` function from Ramda to extract the value of the `"test"` property from each object in the array. **Script Preparation Code** The script preparation code creates an array of 2000 objects with a single property `"test"` set to `'val'`. **Html Preparation Code** The HTML preparation code includes a reference to the Ramda library (version 0.25.0) using a CDN. **Library: Ramda** Ramda is a functional programming library for JavaScript that provides a set of higher-order functions for data processing and manipulation. The `collectBy` function takes two arguments: the input array and a function that extracts a property value from each element in the array. In this case, the extracted value is the `"test"` property. The `project` function takes two arguments: an object with multiple properties and an array of property indices. It returns an object with only the specified properties. **Performance Comparison** Here's a brief summary of each approach: * **"ramdajs collectBy"`: + Pros: More concise and expressive than other approaches, well-suited for functional programming. + Cons: May have higher overhead due to the additional function call. * **"map"`: + Pros: Built-in, widely supported, and efficient. + Cons: Less concise and less expressive than `collectBy`, may require more memory allocation. * **"ramdajs project"`: + Pros: More flexible and powerful than `collectBy` for complex data transformations. + Cons: May be overkill for simple use cases like this one, requires additional setup. **Other Considerations** * The benchmark measures the execution rate per second (`ExecutionsPerSecond`) for each test case, which is a good indicator of performance. * The results are reported for three different browsers and platforms (Chrome 121 on Windows Desktop), which helps to evaluate cross-browser compatibility. **Alternatives** If you're looking for alternative libraries or approaches for data transformation and manipulation in JavaScript, consider: * Lodash: A popular utility library that provides a comprehensive set of functions for data processing. * Underscore.js: Another well-known utility library that offers a wide range of functions for functional programming. * Native JavaScript methods: For simple transformations, you can use native JavaScript methods like `forEach`, `map`, and `reduce`.
Related benchmarks:
ramdajs contains
ramdajs contains
ramda clone vs spread
Ramda range vs Array.from
Comments
Confirm delete:
Do you really want to delete benchmark?