Detailed example of reading speed of js objects

Detailed example of reading speed of js objects

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:
  • Analysis of 4 implementation methods of JavaScript pre-parsing
  • js scope, scope chain and pre-parsing
  • Detailed explanation of JS scope and pre-parsing mechanism
  • JavaScript object-oriented implementation of magnifying glass case
  • 5 commonly used objects in JavaScript
  • JavaScript pre-analysis, object details

<<:  Detailed tutorial on installing Hbase 2.3.5 on Vmware + Ubuntu18.04

>>:  Web developers are concerned about the coexistence of IE7 and IE8

Recommend

CSS Skills Collection - Classics among Classics

Remove the dotted box on the link Copy code The co...

Sharing ideas on processing tens of millions of data in a single MySQL table

Table of contents Project Background Improvement ...

Detailed explanation of several ways to create a top-left triangle in CSS

Today we will introduce several ways to use CSS t...

Detailed installation process of mysql5.7.21 under win10

This article shares the installation of MySQL 5.7...

Detailed explanation of template tag usage (including summary of usage in Vue)

Table of contents 1. Template tag in HTML5 2. Pro...

Solve the problem of ugly blue border after adding hyperlink to html image img

HTML img produces an ugly blue border after addin...

MySQL fuzzy query statement collection

SQL fuzzy query statement The general fuzzy state...

Solution to mysql error when modifying sql_mode

Table of contents A murder caused by ERR 1067 The...

This article will show you the principle of MySQL master-slave synchronization

Table of contents Brief Analysis of MySQL Master-...

Modify the boot time of grub in ubuntu

The online search to modify the grub startup time...

vue front-end HbuliderEslint real-time verification automatic repair settings

Table of contents ESLint plugin installation in H...

VMware kali virtual machine environment configuration method

1|0 Compile the kernel (1) Run the uname -r comma...

Detailed tutorial on deploying apollo with docker

1. Introduction I won’t go into details about apo...