Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sortWith (custom impl vs ramda) #2
(version: 15)
Comparing performance of:
ramda sortWith vs custom impl
Created:
7 years ago
by:
Registered User
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:
function prop(n,r){return void 0===r?r=>prop(n,r):r[n]}function ascend(n,r,t){if(1===arguments.length)return function(r,t){return ascend(n,r,t)};if(2===arguments.length)return function(t){return ascend(n,r,t)};var e=n(r),u=n(t);return e<u?-1:e>u?1:0}function descend(n,r,t){if(1===arguments.length)return function(r,t){return descend(n,r,t)};if(2===arguments.length)return function(t){return descend(n,r,t)};var e=n(r),u=n(t);return e>u?-1:e<u?1:0}function sortWith(r,t){if(1===arguments.length)return function(t){return sortWith(r,t)};var n=r.length;return Array.prototype.slice.call(t,0).sort(function(t,o){for(var e=0,i=0;0===e&&i<n;i++)e=r[i](t,o);return e})} var data = [...Array(3000)].map((v, idx) => { return { value: parseInt(Math.random() * 100, 10), age: parseInt(Math.random() * 100, 10) } }); var valueNameSortR = R.sortWith([ R.descend(R.prop('age')), R.ascend(R.prop('value')) ]); var valueNameSort = sortWith([ descend(prop('age')), ascend(prop('value')) ]);
Tests:
ramda sortWith
valueNameSortR(data)
custom impl
valueNameSort(data)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
ramda sortWith
custom impl
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Android 13; Mobile; rv:121.0) Gecko/121.0 Firefox/121.0
Browser/OS:
Firefox Mobile 121 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
ramda sortWith
27.3 Ops/sec
custom impl
100.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the benchmark. **Benchmark Definition** The provided JSON represents a benchmarking test case for sorting an array of objects using two different approaches: Ramda's `sortWith` function and a custom implementation. **Options Compared** In this benchmark, we have two options being compared: 1. **Ramda's `sortWith` function**: This is a functional programming library that provides various utility functions, including sorting. The `sortWith` function allows you to sort an array of objects based on multiple criteria. 2. **Custom Implementation**: This is the custom implementation of the sorting logic, which is defined in the "Script Preparation Code" section of the benchmark definition. **Pros and Cons** Here's a brief analysis of each approach: * **Ramda's `sortWith` function**: + Pros: Provides a concise and efficient way to sort arrays of objects using multiple criteria. It's also widely adopted and well-maintained. + Cons: May have additional dependencies or overhead compared to a custom implementation. * **Custom Implementation**: + Pros: Can be highly optimized for specific use cases, reducing overhead and improving performance. + Cons: Requires more development effort and may not be as concise or readable as the Ramda implementation. **Library - Ramda** Ramda is a functional programming library that provides various utility functions for data processing, manipulation, and transformation. In this benchmark, it's used to provide the `sortWith` function, which allows sorting arrays of objects based on multiple criteria. **Test Case Explanation** The test case uses Ramda's `sortWith` function to sort an array of 3000 objects based on two criteria: 'age' in descending order and 'value' in ascending order. The custom implementation is compared with this approach to measure their performance differences. If you're interested in the custom implementation, it's a simple recursive function that uses arrow functions to compare elements based on the 'age' and 'value' properties of each object. **Other Considerations** When benchmarking sorting algorithms, several factors come into play: * **Data distribution**: The distribution of data can significantly impact performance. In this case, the data is randomly generated. * **Sorting criteria**: The specific sorting criteria used can affect performance. Here, we're using two criteria: 'age' in descending order and 'value' in ascending order. * **Array size**: The size of the array being sorted can also impact performance. In conclusion, this benchmark provides a useful comparison between Ramda's `sortWith` function and a custom implementation for sorting arrays of objects. It highlights the pros and cons of each approach and allows users to measure their performance differences in a controlled environment.
Related benchmarks:
Javascript Sorting Algorithms
Sorting algorithms comparison (source: https://www.measurethat.net/Benchmarks/Show/3549/0/javascript
Javascript Sorting Algorithmzzz
Javascript Sorting Algorithms large
Comments
Confirm delete:
Do you really want to delete benchmark?