<section id="section"></section>
const section = document.getElementById("section");
section.style.setProperty('--translation', '100');
section.style.setProperty('--translationPx', '100px');
section.style.setProperty('--translationPercentage', '100%');
for (var i = 0; i < 1000; i++) {
const newDiv = document.createElement("div");
const text = document.createTextNode(`${i}`);
newDiv.appendChild(text);
section.appendChild(newDiv);
}
var nodes = document.querySelectorAll("div");
for (var i = 0; i < nodes.length; i++) {
nodes[i].style = "transform: translateY(calc(var(--translation) * 1%))"
}
for (var i = 0; i < nodes.length; i++) {
nodes[i].style = "transform: translateY(var(--translationPercent))"
}
for (var i = 0; i < nodes.length; i++) {
nodes[i].style = "transform: translateY(100%))"
}
for (var i = 0; i < nodes.length; i++) {
nodes[i].style = "transform: translateY(calc(var(--translation) * 1px))"
}
for (var i = 0; i < nodes.length; i++) {
nodes[i].style = "transform: translateY(100px))"
}
for (var i = 0; i < nodes.length; i++) {
nodes[i].style = "transform: translateY(calc(var(--translationPx)))"
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
var(unitless) + calc() + % | |
var(%) + calc() | |
Percentage | |
var(unitless) + calc() + px | |
px | |
var(px) + calc() |
Test name | Executions per second |
---|---|
var(unitless) + calc() + % | 172.3 Ops/sec |
var(%) + calc() | 187.4 Ops/sec |
Percentage | 312.6 Ops/sec |
var(unitless) + calc() + px | 169.7 Ops/sec |
px | 316.9 Ops/sec |
var(px) + calc() | 178.1 Ops/sec |
Benchmark Overview
MeasureThat.net provides a web-based platform for creating and running JavaScript microbenchmarks. The provided JSON data represents a benchmark that tests the performance of CSS calc() and var() functions in different scenarios.
What is being tested?
The benchmark compares the performance of four different test cases:
var(unitless) + calc() + %
: This test case uses the calc() function with unitless value (100%), percentage unit (%), and absolute units (px).var(%) + calc()
: This test case uses the var() function with percentage unit (%) and calc() function.Percentage
: This test case uses only the percentage unit (%) in both calc() and var() functions.var(px) + calc()
: This test case uses absolute units (px) with calc() function and var() function.Options compared
The benchmark compares the performance of these four test cases to determine which one is the fastest.
Pros and Cons of different approaches:
Library used
The benchmark uses JavaScript's built-in calc()
and var()
functions, as well as HTML5 DOM APIs for creating elements and setting styles.
Special JS features/syntax
None mentioned in the provided JSON data. However, it's worth noting that modern JavaScript engines often use various optimizations, such as:
Other alternatives
If you're interested in exploring alternative benchmarking platforms, consider:
These alternatives offer different features and flexibility levels compared to MeasureThat.net, so it's essential to choose the one that best suits your specific needs.