Setting the same value with setAttribute()

Is checking the current value of an attribute with getAttribute() better than setting the same value with setAttribute() over and over.
3 months ago
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0
Test name Executions per second
set the same value 16102210.0 Ops/sec
check and set nothing 12543280.0 Ops/sec
check and set a new value 2094075.0 Ops/sec
set a new value 2681240.0 Ops/sec
check cache and set nothing 1508090000.0 Ops/sec
check cache and set a new value 2535446.0 Ops/sec
HTML Preparation code:
Script Preparation code:
Tests:
  • set the same value

  • check and set nothing

  • check and set a new value

  • set a new value

  • check cache and set nothing

  • check cache and set a new value

Open this result on MeasureThat.net