Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
jquery.css vs getComputedStyle
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser:
Chrome 128
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
jQuery.css
392584.6 Ops/sec
getComputedStyle()
723131.4 Ops/sec
getStyle()
1320561.4 Ops/sec
getStyle2()
766858.2 Ops/sec
HTML Preparation code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <style> #wrap1 { width:300px; margin:10px; padding:10px; border:10px solid black; } #wrap2 { margin:10px; padding:10px; border:10px solid red; } #myDiv { margin:10px; padding:10px; border:10px solid blue; } </style> <div id="wrap1"> <div id="wrap2"> <div id="myDiv"> Test </div> </div> </div>
Script Preparation code:
var myDiv = document.getElementById('myDiv'); var $myDiv = $(myDiv); var getStyle2; // getComputedStyle isn't compatible with all older browsers (notably IE), // so this is a wrapper function that works with those browsers. // From http://www.quirksmode.org/dom/getstyles.html function getStyle(el, styleProp) { if (el.currentStyle) var y = el.currentStyle[styleProp]; else if (window.getComputedStyle) var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp); return y; } if (window.getComputedStyle) { getStyle2 = window.getComputedStyle; } else { getStyle2 = function(el) { return el.currentStyle; } }
Tests:
jQuery.css
var npaddingTop = $myDiv.css('padding-top');
getComputedStyle()
var npaddingTop = getComputedStyle(myDiv).paddingTop;
getStyle()
var npaddingTop = getStyle(myDiv, 'paddingTop');
getStyle2()
var npaddingTop = getStyle2(myDiv)['paddingTop'];