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