Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Access first key using for-in vs object.keys() 2
(version: 0)
Comparing performance of:
for in vs object keys
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var object = { "username.0": ['"589410" is taken'], "username.1": ['"783940" is taken'], "username.2": ['"371395" is taken'], "username.3": ['"692514" is taken'], "username.4": ['"265193" is taken'], "username.5": ['"674381" is taken'], "username.6": ['"501630" is taken'], "username.7": ['"420461" is taken'], "username.8": ['"330937" is taken'], "username.9": ['"322985" is taken'], "username.10": ['"230382" is taken'], "username.11": ['"127276" is taken'], "username.12": ['"654373" is taken'], "username.13": ['"737903" is taken'], "username.14": ['"179119" is taken'], "username.15": ['"307127" is taken'], "username.16": ['"809783" is taken'], "username.17": ['"858057" is taken'], "username.18": ['"628030" is taken'], "username.19": ['"827418" is taken'], "username.20": ['"021759" is taken'], "username.21": ['"901889" is taken'], "username.22": ['"670409" is taken'], "username.23": ['"816120" is taken'], "username.24": ['"570108" is taken'], "username.25": ['"616165" is taken'], "username.26": ['"466825" is taken'], "username.27": ['"849629" is taken'], "username.28": ['"416930" is taken'], "username.29": ['"717803" is taken'], "username.30": ['"709283" is taken'], "username.31": ['"086012" is taken'], "username.32": ['"164108" is taken'], "username.33": ['"176360" is taken'], "username.34": ['"895038" is taken'], "username.35": ['"197542" is taken'], "username.36": ['"935159" is taken'], "username.37": ['"692965" is taken'], "username.38": ['"808858" is taken'], "username.39": ['"892626" is taken'], "username.40": ['"452302" is taken'], "username.41": ['"410983" is taken'], "username.42": ['"806109" is taken'], "username.43": ['"603052" is taken'], "username.44": ['"743256" is taken'], "username.45": ['"951203" is taken'], "username.46": ['"686286" is taken'], "username.47": ['"182002" is taken'], "username.48": ['"752223" is taken'], "username.49": ['"309754" is taken'], "username.50": ['"733286" is taken'], "username.51": ['"081562" is taken'], "username.52": ['"297382" is taken'], "username.53": ['"679007" is taken'], "username.54": ['"722597" is taken'], "username.55": ['"227280" is taken'], "username.56": ['"594096" is taken'], "username.57": ['"538621" is taken'], "username.58": ['"170590" is taken'], "username.59": ['"052273" is taken'], "username.60": ['"699206" is taken'], "username.61": ['"410775" is taken'], "username.62": ['"571899" is taken'], "username.63": ['"556057" is taken'], "username.64": ['"612409" is taken'], "username.65": ['"899716" is taken'], "username.66": ['"108834" is taken'], "username.67": ['"890059" is taken'], "username.68": ['"946135" is taken'], "username.69": ['"720501" is taken'], "username.70": ['"622352" is taken'], "username.71": ['"730299" is taken'], "username.72": ['"453187" is taken'], "username.73": ['"337925" is taken'], "username.74": ['"915580" is taken'], "username.75": ['"835859" is taken'], "username.76": ['"592477" is taken'], "username.77": ['"373133" is taken'], "username.78": ['"399551" is taken'], "username.79": ['"919172" is taken'], "username.80": ['"953271" is taken'], "username.81": ['"258284" is taken'], "username.82": ['"687435" is taken'], "username.83": ['"812398" is taken'], "username.84": ['"125416" is taken'], "username.85": ['"225702" is taken'], "username.86": ['"699948" is taken'], "username.87": ['"549245" is taken'], "username.88": ['"628419" is taken'], "username.89": ['"407965" is taken'], "username.90": ['"804845" is taken'], "username.91": ['"724958" is taken'], "username.92": ['"032163" is taken'], "username.93": ['"134737" is taken'], "username.94": ['"755789" is taken'], "username.95": ['"675369" is taken'], "username.96": ['"490459" is taken'], "username.97": ['"530520" is taken'], "username.98": ['"028948" is taken'], "username.99": ['"159743" is taken'], "username.100": ['"481142" is taken'], "username.101": ['"115216" is taken'], "username.102": ['"665945" is taken'], "username.103": ['"794964" is taken'], "username.104": ['"521910" is taken'], "username.105": ['"427976" is taken'], "username.106": ['"750295" is taken'], "username.107": ['"402068" is taken'], "username.108": ['"257029" is taken'], "username.109": ['"998462" is taken'], "username.110": ['"563071" is taken'], "username.111": ['"765356" is taken'], "username.112": ['"768797" is taken'], "username.113": ['"266323" is taken'], "username.114": ['"379798" is taken'], "username.115": ['"202728" is taken'], "username.116": ['"014080" is taken'], "username.117": ['"670547" is taken'], "username.118": ['"396071" is taken'], "username.119": ['"310120" is taken'], "username.120": ['"074342" is taken'], "username.121": ['"653962" is taken'], "username.122": ['"645640" is taken'], "username.123": ['"949998" is taken'], "username.124": ['"200704" is taken'], "username.125": ['"230204" is taken'], "username.126": ['"169855" is taken'], "username.127": ['"978025" is taken'], "username.128": ['"134299" is taken'], "username.129": ['"492895" is taken'], "username.130": ['"291867" is taken'], "username.131": ['"096199" is taken'], "username.132": ['"083531" is taken'], "username.133": ['"965131" is taken'], "username.134": ['"805910" is taken'], "username.135": ['"907028" is taken'], "username.136": ['"352858" is taken'], "username.137": ['"381160" is taken'], "username.138": ['"546346" is taken'], "username.139": ['"118782" is taken'], "username.140": ['"894351" is taken'], "username.141": ['"484338" is taken'], "username.142": ['"044852" is taken'], "username.143": ['"984997" is taken'], "username.144": ['"657222" is taken'], "username.145": ['"361917" is taken'], "username.146": ['"458560" is taken'], "username.147": ['"089439" is taken'], "username.148": ['"326804" is taken'], "username.149": ['"711826" is taken'], "username.150": ['"669850" is taken'], "username.151": ['"248924" is taken'], "username.152": ['"904142" is taken'], "username.153": ['"456468" is taken'], "username.154": ['"344507" is taken'], "username.155": ['"331980" is taken'], "username.156": ['"428458" is taken'], "username.157": ['"107647" is taken'], "username.158": ['"672777" is taken'], "username.159": ['"059284" is taken'], "username.160": ['"932944" is taken'], "username.161": ['"878861" is taken'], "username.162": ['"509136" is taken'], "username.163": ['"936580" is taken'], "username.164": ['"738630" is taken'], "username.165": ['"427282" is taken'], "username.166": ['"391661" is taken'], "username.167": ['"676491" is taken'], "username.168": ['"525030" is taken'], "username.169": ['"508176" is taken'], "username.170": ['"373249" is taken'], "username.171": ['"600735" is taken'], "username.172": ['"413920" is taken'], "username.173": ['"372463" is taken'], "username.174": ['"675279" is taken'], "username.175": ['"883162" is taken'], "username.176": ['"906543" is taken'], "username.177": ['"207626" is taken'], "username.178": ['"923760" is taken'], "username.179": ['"975595" is taken'], "username.180": ['"497770" is taken'], "username.181": ['"906992" is taken'], "username.182": ['"765407" is taken'], "username.183": ['"806852" is taken'], "username.184": ['"783732" is taken'], "username.185": ['"234423" is taken'], "username.186": ['"292833" is taken'], "username.187": ['"235675" is taken'], "username.188": ['"606273" is taken'], "username.189": ['"969380" is taken'], "username.190": ['"783178" is taken'], "username.191": ['"523958" is taken'], "username.192": ['"184483" is taken'], "username.193": ['"037698" is taken'], "username.195": ['"230532" is taken'], "username.196": ['"726840" is taken'], "username.197": ['"034421" is taken'], "username.198": ['"930613" is taken'], "username.199": ['"318854" is taken'], "username.200": ['"086224" is taken'], "username.201": ['"075967" is taken'], "username.202": ['"415773" is taken'], "username.203": ['"531429" is taken'], "username.204": ['"855044" is taken'], "username.205": ['"976113" is taken'], "username.206": ['"827610" is taken'], "username.207": ['"669825" is taken'], "username.208": ['"428082" is taken'], "username.209": ['"677251" is taken'], "username.210": ['"827606" is taken'], "username.211": ['"667155" is taken'], "username.212": ['"973442" is taken'], "username.213": ['"166994" is taken'], "username.214": ['"953029" is taken'], "username.215": ['"907886" is taken'], "username.216": ['"887977" is taken'], "username.217": ['"655359" is taken'], "username.218": ['"644554" is taken'], "username.219": ['"034788" is taken'], "username.220": ['"369950" is taken'], "username.221": ['"640872" is taken'], "username.222": ['"554729" is taken'], "username.223": ['"535276" is taken'], "username.224": ['"931763" is taken'], "username.225": ['"140600" is taken'], "username.226": ['"250479" is taken'], "username.227": ['"062230" is taken'], "username.228": ['"679543" is taken'], "username.229": ['"819793" is taken'], "username.230": ['"842593" is taken'], "username.231": ['"982153" is taken'], "username.232": ['"731045" is taken'], "username.233": ['"559894" is taken'], "username.234": ['"339339" is taken'], "username.235": ['"114600" is taken'], "username.236": ['"746569" is taken'], "username.237": ['"392032" is taken'], "username.238": ['"561256" is taken'], "username.239": ['"694305" is taken'], "username.240": ['"822116" is taken'], "username.241": ['"701771" is taken'], "username.242": ['"366385" is taken'], "username.243": ['"411339" is taken'], "username.244": ['"462918" is taken'], "username.245": ['"663334" is taken'], "username.246": ['"999596" is taken'], "username.247": ['"024817" is taken'], "username.248": ['"654850" is taken'], "username.249": ['"916517" is taken'], "username.250": ['"918299" is taken'], "username.251": ['"752167" is taken'], "username.252": ['"830566" is taken'], "username.253": ['"064593" is taken'], "username.254": ['"910151" is taken'], "username.255": ['"939911" is taken'], "username.256": ['"898606" is taken'], "username.257": ['"742825" is taken'], "username.258": ['"611174" is taken'], "username.259": ['"299885" is taken'], "username.260": ['"833402" is taken'], "username.261": ['"173387" is taken'], "username.262": ['"559723" is taken'], "username.263": ['"746760" is taken'], "username.264": ['"801140" is taken'], "username.265": ['"467137" is taken'], "username.266": ['"194539" is taken'], "username.267": ['"191832" is taken'], "username.268": ['"275253" is taken'], "username.269": ['"393515" is taken'], "username.270": ['"365134" is taken'], "username.271": ['"593105" is taken'], "username.272": ['"066945" is taken'], "username.273": ['"983869" is taken'], "username.274": ['"632198" is taken'], "username.275": ['"420276" is taken'], "username.276": ['"140496" is taken'], "username.277": ['"374128" is taken'], "username.278": ['"538895" is taken'], "username.279": ['"177766" is taken'], "username.280": ['"383999" is taken'], "username.281": ['"109725" is taken'], "username.282": ['"646143" is taken'], "username.283": ['"275140" is taken'], "username.284": ['"479947" is taken'], "username.285": ['"560848" is taken'], "username.286": ['"024768" is taken'], "username.287": ['"971548" is taken'], "username.288": ['"178188" is taken'], "username.289": ['"607476" is taken'], "username.290": ['"291290" is taken'], "username.291": ['"520210" is taken'], "username.292": ['"996869" is taken'], "username.293": ['"200430" is taken'], "username.294": ['"591433" is taken'], "username.295": ['"727871" is taken'], "username.296": ['"094403" is taken'], "username.297": ['"400902" is taken'], "username.298": ['"054024" is taken'], "username.299": ['"637982" is taken'], "username.300": ['"859442" is taken'], "username.301": ['"411967" is taken'], "username.302": ['"362916" is taken'], "username.303": ['"803966" is taken'], "username.304": ['"923231" is taken'], "username.305": ['"495274" is taken'], "username.306": ['"217516" is taken'], "username.307": ['"442681" is taken'], "username.308": ['"679246" is taken'], "username.309": ['"623828" is taken'], "username.310": ['"922056" is taken'], "username.311": ['"951817" is taken'], "username.312": ['"066028" is taken'], "username.313": ['"967014" is taken'], "username.314": ['"570459" is taken'], "username.315": ['"619413" is taken'], "username.316": ['"563168" is taken'], "username.317": ['"835735" is taken'], "username.318": ['"584092" is taken'], "username.319": ['"741063" is taken'], "username.320": ['"573128" is taken'], "username.322": ['"724751" is taken'], "username.323": ['"021863" is taken'], "username.324": ['"425355" is taken'], "username.325": ['"448634" is taken'], "username.326": ['"175831" is taken'], "username.327": ['"136557" is taken'], "username.328": ['"401721" is taken'], "username.329": ['"629942" is taken'], "username.330": ['"923725" is taken'], "username.331": ['"378302" is taken'], "username.332": ['"792310" is taken'], "username.333": ['"906236" is taken'], "username.334": ['"162424" is taken'], "username.335": ['"241882" is taken'], } function testForIn () { for (const key in object) return key; } function testObjectKeys() { return Object.keys(object)[0]; }
Tests:
for in
testForIn();
object keys
testObjectKeys();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
for in
object keys
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Based on the provided benchmark data, I can infer some information about the performance of these two test cases. **For `in` loop** * The average execution time per second is approximately 18,768,434 (18768434.0). * This suggests that the `in` loop is relatively slow compared to other JavaScript operations. * To improve this, consider using more efficient data structures and algorithms for iterating over objects. **Using `Object.keys()`** * The average execution time per second is approximately 5,398,815 (5398815.0). * This suggests that the `Object.keys()` method is relatively fast compared to other JavaScript operations. * However, it may be worth noting that this method involves creating an array of keys, which can be a memory-intensive operation. **Recommendations** 1. **Use more efficient data structures**: For large objects, consider using Array.prototype.forEach() or Map.prototype.forEach(), which are generally faster and more efficient than iterating over the `in` operator. 2. **Optimize object iteration**: If you must use an `in` loop for some reason, make sure to clear the cache or use a mechanism like requestAnimationFrame() to minimize overhead. 3. **Consider using `Object.entries()` or `Object.values()`**: These methods may be faster and more efficient than iterating over the `in` operator, depending on your specific use case. Keep in mind that these are general suggestions based on the provided benchmark data. The actual performance impact will depend on your specific codebase, requirements, and hardware configuration.
Related benchmarks:
native find vs lodash _.find with null values and object
native findIndex vs lodash find elem
native findIndex vs lodash find element
Access first key using for-in vs object.keys()
Comments
Confirm delete:
Do you really want to delete benchmark?