sorry,  longString[i] is faster than longString[1]
i checked with `--print-opt-code`, but it was too hard to see the difference
2023년 3월 23일 목요일 오후 11시 11분 44초 UTC+9에 Jakob Kummerow님이 작성:

> `longString[1]` is loop-independent and can hence be hoisted out of the 
> loop. `longString[i]` actually has to be loaded from memory in each 
> iteration.
>
> (I haven't spent the time to check whether that's really what's happening. 
> Using `--print-opt-code`, or `--trace-turbo` and Turbolizer, you can check 
> on your own.)
>
>
> On Thu, Mar 23, 2023 at 2:45 PM Jeong HyunJun <rollrat....@gmail.com> 
> wrote:
>
>> hello, I've seen a performance difference depending on whether or not a 
>> variable is used in the loop.
>>
>> let longString = '';
>>
>> for (let i=0;i<10000000;i++) {
>> longString += `${i}`;
>> }
>>
>> console.log(longString.length);
>>
>> let cnt = 0;
>> const st = Date.now();
>>
>> for (let i=0;i<longString.length - 1;i++) {
>>   if (longString[1] === longString[0]) {
>>   /// if (longString[i] === longString[0]) {
>>     cnt ++;
>>   }
>> }
>>
>> console.log(Date.now() - st, cnt);
>>
>> It is twice as slow with longString[i] than with longString[1].
>> What optimizations are causing these results?
>> It doesn't seem to have anything to do with ConsString flattening.
>>
>> -- 
>> -- 
>> v8-users mailing list
>> v8-u...@googlegroups.com
>> http://groups.google.com/group/v8-users
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to v8-users+u...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/v8-users/1ad8718f-5f83-44de-b3de-287625646eb8n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/v8-users/1ad8718f-5f83-44de-b3de-287625646eb8n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/3d9a1140-6d68-40f5-a8cf-8ca42f31ee14n%40googlegroups.com.

Reply via email to