Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object key, typeof === 'function' vs startsWith 'on'
(version: 1)
Comparing performance of:
typeof key === function vs startsWith on
Created:
7 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const attrs = { class: 'test', onclick: e => console.log(e), style: 'color: red;', onfocus: e => console.log(e), }; const count = 1000;
Tests:
typeof key === function
for(let i = 0; i < count; i++) { const el = document.createElement('div'); for(const [k, v] of Object.entries(attrs)) { if(typeof k === 'function') el[k] = v; else el.setAttribute(k, v); } }
startsWith on
for(let i = 0; i < count; i++) { const el = document.createElement('div'); for(const [k, v] of Object.entries(attrs)) { if(k.startsWith('on')) el[k] = v; else el.setAttribute(k, v); } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
typeof key === function
startsWith on
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Browser/OS:
Chrome 140 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
typeof key === function
602.4 Ops/sec
startsWith on
1043.2 Ops/sec
Related benchmarks:
set vs compare functions and set
Test MerciApp getComputedStyle
Compare detecting object keys starting with "on"
Compare createElement vs template String
Compare createElement vs template String - 5 times
Compare createElement vs template String - 100 times
using getAttribute vs innerHtml
xxxx15
Object key, typeof === 'function' vs startsWith 'on' vs 'o' 'n'
Comments
Confirm delete:
Do you really want to delete benchmark?