Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
scrolltop
(version: 13)
Comparing performance of:
vs test
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 class="noid">noid</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 anim (parent, target, duration) { //console.log(parent, target, duration); var oldtime = null; var scrolltoOffset = target.offsetTop - preoffset; function step (framereadytime) { if (!oldtime) oldtime = framereadytime; var progress = framereadytime - oldtime; //console.log(parent, target, duration); if(progress < duration && callback(progress) !== false) { rafid = requestAnimationFrame (step); } } function callback (delta) { parent.scrollTop = scrolltoOffset * delta/duration; } var rafid = requestAnimationFrame (step); setTimeout(function() { cancelAnimationFrame(rafid); }, duration) } function step1 (timestamp) { if (!start) start = timestamp; var progress = timestamp - start; parent.scrollTop = Math.min(progress*goffset / duration, goffset); if (progress < duration) { requestAnimationFrame(step1); } } function anim1 (parent, target, duration) { start = null; goffset = target.offsetTop - preoffset; requestAnimationFrame(step1); }
Tests:
anim (parent, target, duration);
test
1+1
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
test
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):
I'll break down the provided JSON and explain what's being tested, compared, and what pros/cons come with each approach. **Benchmark Definition** The benchmark is defined by two parts: 1. **Script Preparation Code**: This code sets up the necessary variables and functions for the animation: * `gid(id)`: A function that returns an HTML element using its ID. * `duration`, `parent`, `target`, `preoffset`: Variables set based on the `parent` and `target` elements. 2. **Html Preparation Code**: This code defines the HTML structure with two nested `div`s (`parent` and `child`) containing a target element (`target`) and another non-existent element (`noid`). 3. The actual animation function is defined in the Script Preparation Code: `anim(parent, target, duration)`. It takes three parameters: the parent element, the target element, and the animation duration. **Options Compared** Two different approaches are compared: 1. **`anim(parent, target, duration)`**: This is the original implementation of the animation function. 2. **`anim1(parent, target, duration)`**: A modified version of the `anim` function with a few changes: * The `start` variable is removed, and instead, the timestamp is calculated directly in the `step1` function. * The `goffset` variable is set to the target element's offset. **Pros/Cons** The two approaches have different pros and cons: **Original Implementation (`anim(parent, target, duration)`):** Pros: * Easier to understand and maintain * More straightforward code Cons: * Uses a separate `start` variable, which might be considered unnecessary **Modified Implementation (`anim1(parent, target, duration)`):** Pros: * Eliminates the need for a separate `start` variable * Possibly optimized for performance (by avoiding unnecessary calculations) Cons: * More complex code due to the removal of the `start` variable * Might be harder to understand and maintain **Library Used: RequestAnimationFrame** The `requestAnimationFrame` function is used in both implementations. This API allows for smooth animation by scheduling animation frames directly on the browser's event loop. **Special JS Feature/Syntax** None are mentioned, but it's worth noting that the use of `requestAnimationFrame` is a modern JavaScript feature introduced in Safari 5 and supported by most browsers since then. **Alternatives** Other alternatives for animation frameworks or libraries could be used instead of implementing the animation function from scratch. Some popular options include: * jQuery Animation * AnimeJS * GSAP (GreenSock Animation Platform) * Pixi.js Keep in mind that these alternatives might offer more features, flexibility, and performance compared to a custom implementation. I hope this explanation helps you understand what's being tested and compared in the benchmark!
Related benchmarks:
Canvas paths performance
Canvas paths performance without alpha
Canvas paths performance -fixed
PutImageData vs DrawImage Large
Canvas clearing performance v3
Comments
Confirm delete:
Do you really want to delete benchmark?