Tuesday, January 11, 2022

Re: vim9 Benchmark

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

Il giorno martedì 11 gennaio 2022 alle 13:38:08 UTC+1 Bram Moolenaar ha scritto:

Gianmaria Bajo wrote:

> By the way, in that indent benchmark doesn't use lua as it would be done in
> neovim.
>
> For example (neovim 0.6.0)
>
> 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))'
> 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
>
> gVim 8.2 (patch 4058)
>
> vim9script
>
> def g:VimTest(): void
> var totallen = 0
> var start = reltime()
> new
> call setline(1, range(100000))
> for i in range(1, 100000)
> setline(i, ' ' .. getline(i))
> totallen += len(getline(i))
> endfor
> echom totallen
> echom reltimestr(reltime(start))
> bwipe!
> enddef
>
> With nvim I get:
>
> :lua LuaTest()
> 888890
> 0.197217
>
> With gVim I get:
>
> :call VimTest()
> 888890
> 0.308830

The Lua version calls getlines() once, manipulates the array and then
has one call to setlines(), the Vim version calls getline() and
setline() for each line separately. That is not a good comparison.

The idea of the benchmark is to manipulate the text in the buffer, using
one setlines() call is not representing that. Perhaps it should be
changing only every second line.

--
Error:015 - Unable to exit Windows. Try the door.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
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/6c7ee6c6-d501-4622-b6ec-58517419a050n%40googlegroups.com.

No comments: