Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
scrollbind
(version: 1)
Comparing performance of:
scrollto vs scrollto2
Created:
9 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<div id="parent"> <div id="child"> <div id="target">target</div> </div> </div>
Script Preparation code:
function gid(id) { return document.getElementById(id); } duration = 400; parent = gid("parent"); target = gid("target"); preoffset = parent.offsetHeight/2 + parseInt(getComputedStyle(parent).marginTop); function step (parent, scrolltoOffset, duration, oldtime, framereadytime) { if (!oldtime) oldtime = framereadytime; var progress = framereadytime - oldtime; //console.log(parent, target, duration); if(progress < duration) { requestAnimationFrame (step.bind(null, parent, scrolltoOffset, duration, oldtime)); parent.scrollTop = scrolltoOffset * progress/duration; } } function scrollTo (parent, target, duration) { //console.log(parent, target, duration); var oldtime = null; var scrolltoOffset = target.offsetTop - preoffset; var oldtime = null; var cb = step.bind(null, parent, scrolltoOffset, duration, oldtime); requestAnimationFrame (cb); } function scrollTo2 (parent, target, duration) { if(duration > 600) return false; var oldtime = null; var scrolltoOffset = target.offsetTop - preoffset; var step = function (framereadytime) { if (!oldtime) oldtime = framereadytime; var progress = framereadytime - oldtime; if(progress < duration) { requestAnimationFrame (step); parent.scrollTop = scrolltoOffset * progress/duration; } } requestAnimationFrame (step); }
Tests:
scrollto
scrollTo (parent, target, 400);
scrollto2
scrollTo2 (parent, target, 400);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
scrollto
scrollto2
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases. **Benchmark Definition:** The benchmark definition is a set of JavaScript functions that simulate a scrolling animation. The main function `scrollTo` takes three arguments: `parent`, `target`, and `duration`. It calculates the offset to scroll to by subtracting the top offset of the parent element from the top offset of the target element. Then, it uses the `requestAnimationFrame` API to animate the scrolling process. There are two variants of this function: 1. `scrollTo`: This is the first variant. It takes three arguments: `parent`, `target`, and `duration`. It calculates the scroll offset and then calls itself recursively with the updated progress. 2. `scrollTo2`: This is the second variant. It also takes three arguments: `parent`, `target`, and `duration`. However, it has a different implementation. If the duration exceeds 600 milliseconds, it returns false without animating the scrolling process. **Options Compared:** The two variants of the `scrollTo` function are compared to measure their performance differences. The main difference between them is the way they handle the animation progress. **Pros and Cons of Each Approach:** 1. `scrollTo` (Recursive): * Pros: + More elegant and intuitive implementation. + Handles large animation values without exceeding the maximum call stack size. * Cons: + May lead to performance issues due to excessive recursive calls. 2. `scrollTo2` (Iterative): * Pros: + More efficient in terms of memory usage, as it avoids recursive calls. + Faster execution times for large animation values. * Cons: + Less intuitive implementation compared to the recursive version. **Library and Purpose:** The `requestAnimationFrame` API is a built-in JavaScript library that allows for smooth animations by scheduling functions to be executed at specific times. It's used in both variants of the `scrollTo` function to animate the scrolling process. **Special JS Features/Syntax:** There are no special JavaScript features or syntax used in this benchmark definition. **Alternative Approaches:** For animating scrolling, alternative approaches could include: 1. Using a library like Greensock Animation Platform (GSAP) or AnimeJS, which provide more advanced animation capabilities. 2. Utilizing Web Workers to offload the animation processing, potentially improving performance for complex animations. 3. Employing physics-based simulations, such as those using the Cannon.js library, to create more realistic scrolling animations. Keep in mind that these alternatives might introduce additional complexity and may not be suitable for all use cases. In summary, the benchmark definition measures the performance differences between two variants of a scrolling animation function. The main difference lies in their handling of the animation progress, with one approach using recursive calls and the other using iterative updates.
Related benchmarks:
scrolltop
Scroll
window.addEventListener('scroll',CallbackScroll);
Disable Transition via CSS vs Disable transition via Animation.cancel vs Disable transition via Animation.finish 0.1
Comments
Confirm delete:
Do you really want to delete benchmark?