But there might other things that come into play. In neovim setline() seems to be much faster (when it's setting multiple lines).
For example:
======================================================
neovim lua
======================================================
local getlines = vim.api.nvim_buf_get_lines
local setlines = vim.api.nvim_buf_set_lines
local exec = vim.cmd
function LuaTest()
local totallen = 0
local start = vim.fn.reltime()
exec 'new'
exec 'call setline(1, range(100000))'
exec ('echom "After setting lines to range: "' .. vim.fn.reltimestr(vim.fn.reltime(start)))
local bnr = vim.fn.bufnr()
local lines = getlines(bnr, 0, -1, false)
for i = 1, 100000 do
lines[i] = ' ' .. lines[i]
totallen = totallen + lines[i]:len()
end
setlines(bnr, 0, -1, false, lines)
exec ('echom ' .. totallen)
exec ('echom ' .. vim.fn.reltimestr(vim.fn.reltime(start)))
exec 'bwipe!'
end
local setlines = vim.api.nvim_buf_set_lines
local exec = vim.cmd
function LuaTest()
local totallen = 0
local start = vim.fn.reltime()
exec 'new'
exec 'call setline(1, range(100000))'
exec ('echom "After setting lines to range: "' .. vim.fn.reltimestr(vim.fn.reltime(start)))
local bnr = vim.fn.bufnr()
local lines = getlines(bnr, 0, -1, false)
for i = 1, 100000 do
lines[i] = ' ' .. lines[i]
totallen = totallen + lines[i]:len()
end
setlines(bnr, 0, -1, false, lines)
exec ('echom ' .. totallen)
exec ('echom ' .. vim.fn.reltimestr(vim.fn.reltime(start)))
exec 'bwipe!'
end
======================================================
Result:
After setting lines to range: 0.062205
888890
0.200782
888890
0.200782
======================================================
gVim 8.2
======================================================
vim9script
def VimTest1(): void
echom 'VimTest1'
var totallen = 0
var start = reltime()
new
setline(1, range(100000))
echom 'After setting lines to range: ' .. reltimestr(reltime(start))
for i in range(1, 100000)
setline(i, ' ' .. getline(i))
totallen += len(getline(i))
endfor
echom totallen
echom 'After processing loop: ' .. reltimestr(reltime(start))
bwipe!
enddef
def VimTest2(): void
echom 'VimTest2'
var totallen = 0
var start = reltime()
new
setline(1, range(100000))
echom 'After setting lines to range: ' .. reltimestr(reltime(start))
var lines = getline(1, 100000)
for i in range(100000)
lines[i] = ' ' .. lines[i]
totallen += len(lines[i])
endfor
echom 'After processing loop: ' .. reltimestr(reltime(start))
setline(1, lines)
echom 'After setting modified lines: ' .. reltimestr(reltime(start))
echom totallen
echom reltimestr(reltime(start))
bwipe!
enddef
def g:VimTests(): void
VimTest1()
VimTest2()
enddef
def VimTest1(): void
echom 'VimTest1'
var totallen = 0
var start = reltime()
new
setline(1, range(100000))
echom 'After setting lines to range: ' .. reltimestr(reltime(start))
for i in range(1, 100000)
setline(i, ' ' .. getline(i))
totallen += len(getline(i))
endfor
echom totallen
echom 'After processing loop: ' .. reltimestr(reltime(start))
bwipe!
enddef
def VimTest2(): void
echom 'VimTest2'
var totallen = 0
var start = reltime()
new
setline(1, range(100000))
echom 'After setting lines to range: ' .. reltimestr(reltime(start))
var lines = getline(1, 100000)
for i in range(100000)
lines[i] = ' ' .. lines[i]
totallen += len(lines[i])
endfor
echom 'After processing loop: ' .. reltimestr(reltime(start))
setline(1, lines)
echom 'After setting modified lines: ' .. reltimestr(reltime(start))
echom totallen
echom reltimestr(reltime(start))
bwipe!
enddef
def g:VimTests(): void
VimTest1()
VimTest2()
enddef
======================================================
Result:
VimTest1
After setting lines to range: 0.092458
888890
After processing loop: 0.310901
VimTest2
After setting lines to range: 0.110934
After processing loop: 0.241299
After setting modified lines: 0.365874
888890
0.375667
After setting lines to range: 0.092458
888890
After processing loop: 0.310901
VimTest2
After setting lines to range: 0.110934
After processing loop: 0.241299
After setting modified lines: 0.365874
888890
0.375667
Il giorno martedì 11 gennaio 2022 alle 14:18:25 UTC+1 Gianmaria Bajo ha scritto:
I repeated those tests multiple times. It seems to be a bit slower, yes.vim9script
def VimTest1(): void
var totallen = 0
var start = reltime()
newcall setline(1, range(100000))
for i in range(1, 100000)
setline(i, ' ' .. getline(i))
totallen += len(getline(i))
endforechom 'VimTest1'
echom totallen
echom reltimestr(reltime(start))
bwipe!
enddefdef VimTest2(): void
var totallen = 0
var start = reltime()
new
setline(1, range(100000))
var lines = getline(1, 100000)
for i in range(100000)
lines[i] = ' ' .. lines[i]
totallen += len(lines[i])
endfor
setline(1, lines)echom 'VimTest2'
echom totallen
echom reltimestr(reltime(start))
bwipe!
enddefdef g:VimTests(): void
VimTest1()
VimTest2()
enddefIl giorno martedì 11 gennaio 2022 alle 14:07:55 UTC+1 cbl...@256bit.org ha scritto:
On Di, 11 Jan 2022, Gianmaria Bajo wrote:
> Even getting/setting lines in one go (as in the lua version) doesn't improve it for me:
>
> vim9script
>
> def g:VimTest(): void
> var totallen = 0
> var start = reltime()
> new
> setline(1, range(100000))
> var lines = getline(1, 100000)
> for i in range(100000)
> lines[i] = ' ' .. lines[i]
> totallen += len(lines[i])
> endfor
> setline(1, lines)
> echom totallen
> echom reltimestr(reltime(start))
> bwipe!
> enddef
>
> Result:
>
> :call VimTest()
> 888890
> 0.330822
That is even slower?
Mit freundlichen Grüßen
Christian
--
Mit welcher Geschwindigkeit breitet sich das Dunkel aus?
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/17eb9318-270a-44f5-b5e0-093a4df38635n%40googlegroups.com.
No comments:
Post a Comment