<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(var(--translationPx))"
}
for (var i = 0; i < nodes.length; i++) {
nodes[i].style = "transform: translateY(calc(var(--translationPx) * 1))"
}
for (var i = 0; i < nodes.length; i++) {
nodes[i].style = "transform: translateY(calc(var(--translationPercent) * 1))"
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
var(unitless) + calc() + % | |
var(%) | |
Percentage | |
var(unitless) + calc() + px | |
px | |
var(px) | |
var(px) + calc() | |
var(%) + calc() |
Test name | Executions per second |
---|---|
var(unitless) + calc() + % | 452.4 Ops/sec |
var(%) | 557.3 Ops/sec |
Percentage | 604.7 Ops/sec |
var(unitless) + calc() + px | 441.2 Ops/sec |
px | 594.9 Ops/sec |
var(px) | 529.2 Ops/sec |
var(px) + calc() | 461.4 Ops/sec |
var(%) + calc() | 469.4 Ops/sec |
Let's break down the provided benchmark and explain what's being tested.
Overview The benchmark is designed to measure the performance of CSS calc() and var() functions in JavaScript, specifically when used with different units (unitless, percentage, absolute values).
Benchmark Definition The benchmark definition defines a test case that creates a series of div elements with dynamic styles using calc() and var() functions. The test cases are:
var(unitless) + calc() + %
var(%)
Percentage
var(unitless) + calc() + px
px
var(px)
var(px) + calc()
Test Cases
var(unitless) + calc() + %
: This test case uses the var() function with a unitless value and the calc() function with a percentage value. The benchmark measures how fast the browser can apply this style to all div elements.var(%)
: This test case uses only the var() function with a percentage value. The benchmark measures how fast the browser can apply this style to all div elements.Percentage
: This test case uses only the calc() function with a percentage value. The benchmark measures how fast the browser can apply this style to all div elements.var(unitless) + calc() + px
: This test case combines var() and calc() functions with different units (unitless and absolute values). The benchmark measures how fast the browser can apply this style to all div elements.px
: This test case uses only the calc() function with an absolute value (pixel). The benchmark measures how fast the browser can apply this style to all div elements.var(px)
: This test case uses the var() function with a unit of pixel. The benchmark measures how fast the browser can apply this style to all div elements.var(px) + calc()
: This test case combines the var() and calc() functions with different units (pixel and percentage). The benchmark measures how fast the browser can apply this style to all div elements.var(%) + calc()
: This test case combines both var() and calc() functions with different units (percentage and absolute values). The benchmark measures how fast the browser can apply this style to all div elements.Results The provided results show the execution speed of each test case on a Chrome 118 browser running on a Mac OS X 10.15.7 device. The faster execution speed indicates better performance for each test case.
In general, the benchmark suggests that:
Keep in mind that these results are specific to the provided benchmarking scenario and might not be representative of all browsers or use cases.