1. Accessing literals and local variables is the fastest, while accessing array elements and object members is relatively slow. When accessing an object member, the prototype chain is searched, just like the scope chain. 2. If the member found is too deep in the prototype chain, access speed will be slow. So try to minimize the number of searches and nesting depth of object members. Examples// Perform two object member searches function hasEitherClass(element, className1, className2) { return element.className === className1 || element.className === className2; } //Optimization, if the variable does not change, you can use a local variable to save the search content function hasEitherClass(element, className1, className2) { const currentClassName = element.className; return currentClassName === className1 || currentClassName === className2; } Content extension: js object operation performance issues 1 The longer the string is, the time it takes to use str+="xxx" will increase significantly (almost exponentially). 2 When the object array has only 400 elements, the access time to the properties and methods of each element reaches 1/4 millisecond for each property or method! If an element has 10 attributes, then a traversal of the array will take at least 1 second, which is terrible. 3 FileSystem operations, especially write operations, are almost proportional to the square of the length of the string to be written. 4 Do not use your own methods to perform string operations, especially replacement, search, and comparison; I don't have a good grasp of regular expressions. When using custom functions, I found that in the traversal mentioned in 2) above, The custom function takes up to 80% of the total time! This concludes this article on the detailed example of js object reading speed. For more information about js object reading speed, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed tutorial on installing Hbase 2.3.5 on Vmware + Ubuntu18.04
>>: Web developers are concerned about the coexistence of IE7 and IE8
I joined a new company these two days. The compan...
introduction Sometimes, if there are a large numb...
1. Float: The main purpose is to achieve the effe...
Table of contents Preface zx library $`command` c...
Table of contents Before MySQL 5.6 After MySQL 5....
All blogs listed below are original and uniquely ...
Preface: Vue3.0 implements echarts three-dimensio...
Sometimes we save a lot of duplicate data in the ...
Question: In index.html, iframe introduces son.htm...
<br />Semanticization cannot be explained in...
After Vmvare sets the disk size of the virtual ma...
Writing method 1: update sas_order_supply_month_p...
Awk is an application for processing text files, ...
Table of contents 1. Overview of MySQL Logical Ar...
Written in front Nginx is not just a reverse prox...