Hi,

On Sat, Nov 20, 2021 at 11:32 AM Yegappan Lakshmanan
<[email protected]> wrote:
>
> On Fri, Nov 19, 2021 at 5:27 AM lacygoill <[email protected]> wrote:
>>
>> Interestingly enough, :highlight is faster than hlset():
>>
>> vim9script
>> var time = reltime()
>> def Func()
>>     for i: number in range(100'000)
>>         highlight ErrorMsg term=standout ctermfg=253 ctermbg=168 
>> guifg=#dadada guibg=#d75f87
>>     endfor
>> enddef
>> Func()
>> (reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to run 
>> Func()')->setline(1)
>>
>> 0.343 seconds to run Func()
>>
>> vim9script
>> var time = reltime()
>> def Func()
>>     for i: number in range(100'000)
>>         [{
>>             name: 'ErrorMsg',
>>             ctermfg: '253',
>>             ctermbg: '168',
>>             guibg: '#d75f87',
>>             guifg: '#dadada',
>>             term: {standout: true},
>>         }]->hlset()
>>     endfor
>> enddef
>> Func()
>> (reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to run 
>> Func()')->setline(1)
>>
>> 0.511 seconds to run Func()
>>
>> The discrepancy is more pronounced at the script level:
>>
>> vim9script
>> var time = reltime()
>> for i in range(100'000)
>>     highlight ErrorMsg term=standout ctermfg=253 ctermbg=168 guifg=#dadada 
>> guibg=#d75f87
>> endfor
>> (reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to run the 
>> script')->setline(1)
>>
>> 0.523 seconds to run the script
>>
>> vim9script
>> var time = reltime()
>> for i: number in range(100'000)
>>     [{
>>         name: 'ErrorMsg',
>>         ctermfg: '253',
>>         ctermbg: '168',
>>         guibg: '#d75f87',
>>         guifg: '#dadada',
>>         term: {standout: true},
>>     }]->hlset()
>> endfor
>> (reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to run the 
>> script')->setline(1)
>>
>> 1.268 seconds to run the script
>>
>>
>
> I took a look at this issue. It looks like just populating the attributes 
> itself takes time. For example,
> if you source the following script:
>
> vim9script
> var time = reltime()
> var attr: list<dict<any>>
> for i: number in range(100'000)
>     attr = [{
>         name: 'ErrorMsg',
>         ctermfg: '253',
>         ctermbg: '168',
>         guibg: '#d75f87',
>         guifg: '#dadada',
>         term: {standout: true},
>     }]
> endfor
> (reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to run the 
> script')->setline(1)
>
> The above script takes around 0.630 seconds in my setup (without any calls to 
> hlset()).
> So it looks like most of the time is spent outside of the hlset() function.
>

If I modify the script so that the attributes are initialized outside
of the for loop, then the
script runs faster (around 0.520 seconds):

vim9script
var attr: list<dict<any>> = [{
    name: 'ErrorMsg',
    ctermfg: '253',
    ctermbg: '168',
    guibg: '#d75f87',
    guifg: '#dadada',
    term: {standout: true},
}]
var time = reltime()
for i: number in range(100'000)
    attr->hlset()
endfor
(reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to
run the script')->setline(1)

Similarly, if hlset() is called for a large number of attributes in a
single invocation, then
the script runs faster (0.230 seconds):

vim9script
var l: list<dict<any>> = []
for i: number in range(100'000)
    l->extend([{
        name: 'ErrorMsg',
        ctermfg: '253',
        ctermbg: '168',
        guibg: '#d75f87',
        guifg: '#dadada',
        term: {standout: true},
    }])
endfor
var time = reltime()
l->hlset()
(reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to
run the script')->setline(1)

Regards,
Yegappan

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/CAAW7x7kZdnmypYAscFLD25tOEAieDQvtG51CNF3_32WLEfDuLQ%40mail.gmail.com.

Raspunde prin e-mail lui