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