Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
debounce ramda vs. vanila
(version: 0)
Comparing performance of:
ramda vs vanila
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 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)
vanila
debounceV(handler, 0)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
ramda
vanila
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/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
ramda
19037360.0 Ops/sec
vanila
120416464.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares two implementations of the debounce function: `debounceR` (using Ramda) and `debounceV` (using vanilla JavaScript). The benchmark is designed to test the performance difference between these two approaches. **Options Compared** * `debounceR`: This implementation uses Ramda's functional programming library. It creates a curry (a higher-order function that takes multiple arguments as input) for the debounce function. + Pros: - More concise and expressive code - Utilizes the benefits of functional programming, such as immutability and recursion + Cons: - May have additional overhead due to the need to curry the function - Requires Ramda library to be included * `debounceV`: This implementation uses a simple, imperative approach. + Pros: - Lightweight and easy to understand - No external dependencies required + Cons: - May not be as concise or expressive as the Ramda implementation **Other Considerations** * **Library Usage**: The benchmark includes the Ramda library for `debounceR`. This library provides a set of functional programming utilities, including currying and mapping functions. * **Special JS Feature/Syntax**: None are mentioned in this specific benchmark. **Benchmark Preparation Code** The provided script preparation code defines the two debounce functions: `debounceR` (using Ramda) and `debounceV` (using vanilla JavaScript). The `handler` function is used as a placeholder for any function that needs to be debounced. **Individual Test Cases** The benchmark consists of two test cases: 1. `ramda`: This test case uses the `debounceR` implementation with a delay of 0 and the `handler` function. 2. `vanila`: This test case uses the `debounceV` implementation with a delay of 0 and the `handler` function. **Latest Benchmark Result** The provided benchmark result shows the performance data for both test cases, including executions per second. The results indicate that the vanilla JavaScript implementation (`debounceV`) outperforms the Ramda implementation (`debounceR`) in this specific benchmark. **Alternatives** Other alternatives to debounce functions include: * Using a library like Lodash or Moment.js, which provide built-in debounce and throttle functions. * Implementing a custom debounce function using an existing library or framework (e.g., React). * Using a different approach, such as using a timeout-based approach without creating a new function for each event. Keep in mind that the choice of implementation depends on the specific use case, performance requirements, and personal preference.
Related benchmarks:
Debounce
debounce ramda vs. lodash
debounce ramda vs. underscore
debounce ramda vs underscore
Comments
Confirm delete:
Do you really want to delete benchmark?