jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Comparing use of HTMLElement.offsetWidth and jQuery .width() to get width of SVG text. Also check for height.
Mozilla explicitly considers HTMLElement.offsetWidth/Height to be invalid for SVG and report these as undefined. IE10 also reports undefined. With $.width()/.height(), Mozilla and IE10 report values of 0.
Mozilla and IE10 produce expected values with .getComputedTextLength(), though that only helps for width, not height.
Chrome and Safari give nonzero values for all of the above.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<svg>
<text x="156" y="90" width="190" height="40.22" style="display: inline;"
<tspan pointer-events="none" justification="start">
<tspan pointer-events="none">
<tspan id="inner_span" pointer-events="none" x="0" y="33" font-family="Arial" font-size="36" fill="#000000" color="#000000">Hello world</tspan>
</tspan>
</tspan>
</text>
</svg>
var width, height;
var textSelector = $("#inner_span");
width = 0;
height = 0;
textSelector = 0;
Ready to run.
Test | Ops/sec | |
---|---|---|
use offsetWidth and offsetHeight |
| ready |
use getBBox .width and .height |
| ready |
use getComputedTextLength() |
| ready |
use getComputedStyle |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.