<svg width="150" height="150">
<text id="test1" y="50">test1</text>
<text id="test2" y="100"></text>
<text id="test3" y="150">test3</text>
</svg>
var test1 = document.getElementById('test1');
var test2 = document.getElementById('test2');
var test3 = document.getElementById('test3');
test1.getBBox().y;
test2.getBBox().y;
test3.getBBox().y;
test1.getBoundingClientRect().y;
test2.getBoundingClientRect().y;
test3.getBoundingClientRect().y;
test1.y.baseVal.getItem(0).value;
test2.y.baseVal.getItem(0).value;
test3.y.baseVal.getItem(0).value;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
getBBox | |
getBoundingClientRect | |
baseVal |
Test name | Executions per second |
---|---|
getBBox | 401223.8 Ops/sec |
getBoundingClientRect | 294641.5 Ops/sec |
baseVal | 2269724.5 Ops/sec |
Overview of the Benchmark
The provided JSON represents a JavaScript benchmarking test created on MeasureThat.net. The test compares the performance of three methods: getBBox()
, getBoundingClientRect()
, and baseVal
. Each method is tested in isolation, with multiple executions per second.
Methods being Compared
getBBox()
due to its inclusion of the element's offset from the viewport.y
property in the provided HTML, which defines the y-coordinate of an SVG text element.Options being Compared
The options being compared are:
getBBox()
: The native JavaScript API for getting the bounding box coordinates.getBoundingClientRect()
: The native JavaScript API for getting the size and position of an element relative to the viewport.baseVal
: A method that returns the value of a CSS base unit, used in this case to get the y-coordinate of an SVG text element.Pros and Cons of each approach
getBBox()
due to the inclusion of offset valuesLibrary and Special JS Features
The provided HTML uses an <svg>
element, which indicates that this benchmark is using SVG (Scalable Vector Graphics) to display the text elements. The baseVal
method seems to be related to SVG attributes.
There are no special JavaScript features being tested in this benchmark.
Other Alternatives
If you wanted to add more alternatives to this benchmark, you could consider:
getOffsetWidth()
and getOffsetHeight()
for getting element offsets.Keep in mind that the specific alternatives will depend on the goals and focus of your benchmark.