robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
1.2 KiB60 linesraw
1local t = require('test.testutil')
2local describe, it = t.describe, t.it
3local N = 20
4
5local function tcall(f, ...)
6  local ts = vim.uv.hrtime()
7  for _ = 1, N do
8    f(...)
9  end
10  return ((vim.uv.hrtime() - ts) / 1000000) / N
11end
12
13local function build_shared(n)
14  local t = {}
15  local a = {}
16  local b = {}
17  local c = {}
18  for _ = 1, n do
19    t[#t + 1] = {}
20    local tl = t[#t]
21    for _ = 1, n do
22      tl[#tl + 1] = a
23      tl[#tl + 1] = b
24      tl[#tl + 1] = c
25    end
26  end
27  return t
28end
29
30local function build_unique(n)
31  local t = {}
32  for _ = 1, n do
33    t[#t + 1] = {}
34    local tl = t[#t]
35    for _ = 1, n do
36      tl[#tl + 1] = {}
37    end
38  end
39  return t
40end
41
42describe('vim.deepcopy()', function()
43  local function run(name, n, noref)
44    it(string.format('%s entries=%d noref=%s', name, n, noref), function()
45      local t = name == 'shared' and build_shared(n) or build_unique(n)
46      local d = tcall(vim.deepcopy, t, noref)
47      print(string.format('%.2f ms', d))
48    end)
49  end
50
51  run('unique', 50, false)
52  run('unique', 50, true)
53  run('unique', 2000, false)
54  run('unique', 2000, true)
55
56  run('shared', 50, false)
57  run('shared', 50, true)
58  run('shared', 2000, false)
59  run('shared', 2000, true)
60end)