Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
debounce ramda vs. lodash
(version: 0)
Comparing performance of:
ramda vs lodash
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script>
Script Preparation code:
var debounceR = R.curry((config, fn) => { const { delay, initialInstant = false } = (R.is(Number, config) ? { delay: config } : config); let timer = null; let firstCall = false; return (...args) => new Promise((resolve, reject) => { const safeCall = () => { try { resolve(fn.apply(window, args)); } catch (e) { reject(e); } }; if (!firstCall) { firstCall = true; if (initialInstant) { safeCall(); return; } } if (!R.isNil(timer)) { clearTimeout(timer); } timer = setTimeout(safeCall, delay); }); }); var debounceV = (func, timeout) => { let timer; return (...args) => { clearTimeout(timer); timer = setTimeout(() => { func.apply(this, args); }, timeout); }; } var handler = () => {};
Tests:
ramda
debounceR({delay: 0}, handler)
lodash
_.debounce(handler, 0)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
ramda
lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0
Browser/OS:
Chrome 145 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
ramda
7383790.5 Ops/sec
lodash
10295509.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Explanation** The provided benchmark tests the performance of two debounce functions: `debounceR` (from Ramda) and `debounceV` (a custom implementation). Debounce is a function that limits the execution of another function to a specific time interval, preventing it from being called too frequently. **Options Compared** Two options are compared: 1. **Ramda's `debounceR`**: This function uses the Ramda library to implement debounce. It takes two arguments: a configuration object and a handler function. The configuration object can specify the delay time and whether the initial instant should be executed immediately. 2. **Custom `debounceV` implementation**: This is a simple, non-library-based implementation of debounce. It also takes two arguments: a function to execute and a timeout. **Pros and Cons** **Ramda's `debounceR`**: Pros: * Uses the Ramda library, which provides functional programming utilities. * Allows for more configuration options (delay time and initial instant). Cons: * Adds overhead due to the use of an external library. * May not be suitable for projects that require a lightweight implementation. **Custom `debounceV` implementation**: Pros: * Lightweight and easy to understand. * Can be optimized for specific use cases. Cons: * Limited configuration options (only timeout). * May not be as performant as the Ramda implementation due to the lack of optimization. **Library: Lodash** The benchmark also tests `_.debounce` from Lodash. This function is similar to Ramda's `debounceR`, but with a simpler API and no configuration object. **Pros and Cons** * _.debounce: + Simple and easy to use. + Fast execution time due to its optimized implementation. + Limited configuration options (only timeout). + Adds overhead due to the use of an external library. **Special JS Feature: `window`** The custom implementation uses `window` as the context for the handler function. This is a global object in JavaScript that represents the window or browser environment. In this case, it's used to execute the handler function with the correct context. **Other Considerations** * The benchmark is run on a single device (Chrome 127) and platform (Desktop, Windows). This may not be representative of all possible environments. * The execution per second value indicates how many times the benchmark function was executed in one second. A higher value typically indicates better performance. * The raw UA string includes additional information about the browser, version, and device type. **Alternatives** * Other debounce libraries or implementations exist, such as `lodash-debounce`, `jquery-debounce`, or custom implementations like the one used in this benchmark. * Alternative approaches to debouncing include using a timer-based approach or a more complex algorithm that takes into account multiple factors (e.g., user interaction, network latency).
Related benchmarks:
lodash omit vs spread omit vs spread omit using babel
lodash omit vs spread omit vs delete omit
Deep merge: lodash vs ramda vs Object spread
Lodash isUndefined vs isNil
lodash omit vs spread omit modified
Comments
Confirm delete:
Do you really want to delete benchmark?