search
HomeWeb Front-endJS TutorialFor loop performance comparison to improve the efficiency of for loop_javascript skills

Compared with for(int i=1,n=tempUser.length;i for(int i=1,;i I am used to for(int i=1,;i I immediately I tested it and found that the performance difference is very small, and the latter is even more efficient.
Although I got this result, it was completely opposite to what I thought. Of course, the answer is pretty much the same.
Today I found another senior’s blog that had a response to this post. He did a test, and the content was roughly that the problem in the previous post should be similar, but he conducted a more in-depth test and came to the conclusion: in the case of for (int i=0;iI also did a test:

Copy the code The code is as follows:

class Program {
static void Main(string[] args) {
string s;
s = Console.ReadLine();

while(s != "0") {
Person p = new Person(10000000);

Console.WriteLine("for(int i=0;iConsole.WriteLine("Starting.. .");
long l1 = DateTime.Now.Ticks;

for(int i = 0; i //Console. Write(lenArray[i]);

}
long l2 = DateTime.Now.Ticks;

Console.WriteLine("Ending.nTime is : " (l2 - l1). ToString());

Console.WriteLine("for(int i=0,n=lenArray.length;iConsole.WriteLine("Starting... ");

long l3 = DateTime.Now.Ticks;
for(int i = 0, n = p.Child.Alias.Length; i / /Console.Write(lenArray[i]);

}
long l4 = DateTime.Now.Ticks;
Console.WriteLine("Ending.nTime is : " (l4 - l3). ToString());
s = Console.ReadLine();
}
Console.Read();
}
}

For loop performance comparison to improve the efficiency of for loop_javascript skills

The larger the amount of data, the larger the class, and the more obvious the difference.

Conclusion: The impact should be that the variable must access the next-level variable in each loop. If it is just a simple a.length, the compiler may have optimized such a loop operation and saved a.length to memory or a place larger than memory, but multi-level is not so lucky.
We all know the for(int i=0;i

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
解决kernel_security_check_failure蓝屏的17种方法解决kernel_security_check_failure蓝屏的17种方法Feb 12, 2024 pm 08:51 PM

Kernelsecuritycheckfailure(内核检查失败)就是一个比较常见的停止代码类型,可蓝屏错误出现不管是什么原因都让很多的有用户们十分的苦恼,下面就让本站来为用户们来仔细的介绍一下17种解决方法吧。kernel_security_check_failure蓝屏的17种解决方法方法1:移除全部外部设备当您使用的任何外部设备与您的Windows版本不兼容时,则可能会发生Kernelsecuritycheckfailure蓝屏错误。为此,您需要在尝试重新启动计算机之前拔下全部外部设备。

Win10如何卸载Skype for Business?电脑上的skype怎么彻底卸载方法Win10如何卸载Skype for Business?电脑上的skype怎么彻底卸载方法Feb 13, 2024 pm 12:30 PM

Win10skype可以卸载吗是很多用户们都想知道的一个问题,因为很多的用户们发现自己电脑上的默认程序上有这个应用,担心删除后会影响到系统的运行,下面就让本站来为用户们来仔细的介绍一下Win10如何卸载SkypeforBusiness吧。Win10如何卸载SkypeforBusiness1、在电脑桌面点击Windows图标,再点击设置图标进入。2、点击“应用”。3、在搜索框中输入“Skype”,点击选中找到的结果。4、点击“卸载”。5

JavaScript怎么用for求n的阶乘JavaScript怎么用for求n的阶乘Dec 08, 2021 pm 06:04 PM

用for求n阶乘的方法:1、使用“for (var i=1;i<=n;i++){}”语句控制循环遍历范围为“1~n”;2、循环体中,使用“cj*=i”将1到n的数相乘,乘积赋值给变量cj;3、循环结束后,变量cj的值就n的阶乘,输出即可。

foreach和for循环的区别是什么foreach和for循环的区别是什么Jan 05, 2023 pm 04:26 PM

区别:1、for通过索引来循环遍历每一个数据元素,而forEach通过JS底层程序来循环遍历数组的数据元素;2、for可以通过break关键词来终止循环的执行,而forEach不可以;3、for可以通过控制循环变量的数值来控制循环的执行,而forEach不行;4、for在循环外可以调用循环变量,而forEach在循环外不能调用循环变量;5、for的执行效率要高于forEach。

Python中的常见流程控制结构有哪些?Python中的常见流程控制结构有哪些?Jan 20, 2024 am 08:17 AM

Python中常见的流程控制结构有哪几种?在Python中,流程控制结构是用来决定程序的执行顺序的重要工具。它们允许我们根据不同的条件执行不同的代码块,或者重复执行一段代码。下面将介绍Python中常见的流程控制结构,并提供相应的代码示例。条件语句(if-else):条件语句允许我们根据不同的条件执行不同的代码块。它的基本语法是:if条件1:#当条件

利用Go语言for循环快速实现翻转功能利用Go语言for循环快速实现翻转功能Mar 25, 2024 am 10:45 AM

使用Go语言实现翻转功能可以通过for循环非常快速地实现。翻转功能是将字符串或数组中的元素顺序颠倒,可以应用在很多场景中,例如字符串翻转、数组元素翻转等。下面我们来看一下如何利用Go语言的for循环来实现字符串和数组的翻转功能,并附上具体的代码示例。字符串翻转:packagemainimport("fmt")fun

Java中迭代器和for循环的优劣比较Java中迭代器和for循环的优劣比较Apr 22, 2023 pm 02:28 PM

1.概念理解for循环:是支持迭代的一种通用结构,是最有效,最灵活的循环结构迭代器:是通过集合的iterator()方法得到的,所以我们说它是依赖于集合而存在的Foreach:通过阅读源码我们还发现一个Iterable接口。它包含了一个产生Iterator对象的iterator()方法,而且将Iterator对象被foreach用来在序列中移动。对于任何实现Iterable接口的对象都可以使用。2.效率实例ArrayList中的效率对比:Listintegers=Lists.newArrayLi

6个实例,8段代码,详解 Python 中的 For 循环6个实例,8段代码,详解 Python 中的 For 循环Apr 11, 2023 pm 07:43 PM

Python 支持for循环,它的语法与其他语言(如JavaScript 或Java)稍有不同。下面的代码块演示如何在Python中使用for循环来遍历列表中的元素:上述的代码段是将三个字母分行打印的。你可以通过在print语句的后面添加逗号&ldquo;,&rdquo;将输出限制在同一行显示(如果指定打印的字符很多,则会&ldquo;换行&rdquo;),代码如下所示:当你希望通过一行而不是多行显示文本中的内容时,可以使用上述形式的代码。Python还提供了内置

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools