یک میلیون دیتا رو با 4 روش Loop یا حلقه در JavaScript مقایسه کردم
واینکه خیلی جالبه هرکدومشون در جای خاصی کاربرد دارن
هر 4 تا یک کار رو میکنن ولی جزییات ریزی داره که خودتون با R&D کردن میتونید به دستش بیارید
از console.time برای اینکه بدونم هرکدوم در چه زمانی خروجی رو بهم میده استفاده کردم
داخل پست هر 4 مورد با کدهاش و اینکه دو بار خروجی run برنامه رو هم آوردم که زمان هاشون رو نشون میشه
نکته جالب اینه که هر بار یک نتیجه متفاوت به من میده!
و من اومدم برای دیتاهای بالای یک میلیون . . . 10 بار تست گرفتم که نتیجه این شد برای دیتاهای بزرگ از :
forLoop استفاده کنیم چون بهترین عملکرد رو داره
و برای دیتاهای کمتر که من 100 هزار رو تست کردم بعد از 10 بار تست نتیجه :
forEach بهترین گزینه هستش
برای اطمینان بیشتر خودتون هم تست کنید
#webinarfarsi #javascript #performance
ترجمه:
A pure and conceptual point from a small corner in the big world of performance
I compared a million data with 4 Loop methods in JavaScript
And what is very interesting is that each of them is used in a special place
All 4 of them do the same thing, but there are small details that you can get by yourself with R&D
I used console.time to know when each of them gives me the output
In the post, I have included all 4 items with their codes and the output of running the program twice, which shows their times.
The interesting thing is that it gives me a different result every time!
And I came for data above one million. . . I tested 10 times, and the result was this: for large data from:
use forLoop because it has the best performance
And for less data, I tested 100,000 and after 10 tests, the result is:
forEach is the best option
Test yourself for more certainty
#webinarfarsi #javascript #performance
I compared a million data with 4 Loop methods in JavaScript
And what is very interesting is that each of them is used in a special place
All 4 of them do the same thing, but there are small details that you can get by yourself with R&D
I used console.time to know when each of them gives me the output
In the post, I have included all 4 items with their codes and the output of running the program twice, which shows their times.
The interesting thing is that it gives me a different result every time!
And I came for data above one million. . . I tested 10 times, and the result was this: for large data from:
use forLoop because it has the best performance
And for less data, I tested 100,000 and after 10 tests, the result is:
forEach is the best option
Test yourself for more certainty
#webinarfarsi #javascript #performance