Commit cea6b117 authored by S Anand's avatar S Anand

TST: setting stylesheet is faster than setting DOM attributes

parent 92aa2dc3
......@@ -25,5 +25,32 @@ describe('G.style and G.styles', function() {
$('#styleTest').remove()
})
.appendTo('head')
});
})
function timeit(fn) {
var time = +new Date()
fn()
return +new Date() - time
}
it('is faster than setting styles on DOM elements', function() {
// #content contains a large number of <b> elements
for (var html=[], i=0; i<10000; i++) {
html.push('<b>' + i + '</b>')
}
$('#content').html(html.join(''))
$('<style>#content b { color: red }</style>').appendTo('head')
var b_style = G.style('#content b'),
b_elems = document.querySelectorAll('#content b')
function set_style(key, value) {
for (var i=0, elem; elem=b_elems[i]; i++)
elem[key] = value
}
assert.ok(
timeit(function() { set_style('color', 'blue') }) >
timeit(function() { b_style.style.color = 'red' }),
'Stylesheet color is faster than DOM attribute color'
)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment