Created
December 10, 2018 19:36
-
-
Save lambdalisue/ab683aca933422654b4f6d8f4d37f8de to your computer and use it in GitHub Desktop.
compare old/new vital.data.list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s:Benchmark = vital#vital#import('Vital.Benchmark') | |
let s:Old = vital#vital#import('Data.List') | |
let s:New = vital#vital#import('Vital.List') | |
function! s:map() abort | |
let list = repeat(['hello'], 1000) | |
echo 'map()' | |
echo printf( | |
\ ' Old: %f sec', | |
\ s:Benchmark.timeit({ -> s:OldList.map(list, { v -> toupper(v) }) }) | |
\) | |
echo printf( | |
\ ' New: %f sec', | |
\ s:Benchmark.timeit({ -> s:NewList.map(list, { v -> toupper(v) }) }) | |
\) | |
endfunction | |
function! s:filter() abort | |
let list = range(1000) | |
echo 'filter()' | |
echo printf( | |
\ ' Old: %f sec', | |
\ s:Benchmark.timeit({ -> s:OldList.filter(list, { v -> v % 2 is# 0 }) }) | |
\) | |
echo printf( | |
\ ' New: %f sec', | |
\ s:Benchmark.timeit({ -> s:NewList.filter(list, { v -> v % 2 is# 0 }) }) | |
\) | |
endfunction | |
function! s:compare(name, fn1, fn2) abort | |
let lhs = s:Benchmark.timeit(a:fn1) | |
let rhs = s:Benchmark.timeit(a:fn2) | |
echo printf("%s\t%f sec\t%f sec\t%f", a:name, lhs, rhs, lhs / rhs) | |
endfunction | |
echo "Fn\t\tOld \tNew \tRatio" | |
call s:compare( | |
\ "map\t", | |
\ { -> s:Old.map(range(1000), { v -> v * 2 }) }, | |
\ { -> s:New.map(range(1000), { v -> v * 2 }) }, | |
\) | |
call s:compare( | |
\ "filter\t", | |
\ { -> s:Old.filter(range(1000), { v -> v % 2 is# 0 }) }, | |
\ { -> s:New.filter(range(1000), { v -> v % 2 is# 0 }) }, | |
\) | |
call s:compare( | |
\ "reduce\t", | |
\ { -> s:Old.foldl1({ a, v -> a + v }, range(1000)) }, | |
\ { -> s:New.reduce(range(1000), { a, v -> a + v }) }, | |
\) | |
" foldr1 raise maxdepth exception for range(100) | |
call s:compare( | |
\ 'reduce_right', | |
\ { -> s:Old.foldr1({ a, v -> a + v }, range(10)) }, | |
\ { -> s:New.reduce_right(range(10), { a, v -> a + v }) }, | |
\) | |
call s:compare( | |
\ "flatten\t", | |
\ { -> s:Old.flatten(repeat([['hello']], 1000)) }, | |
\ { -> s:New.flatten(repeat([['hello']], 1000)) }, | |
\) | |
call s:compare( | |
\ "find_index", | |
\ { -> s:Old.find_index(range(1000), { v -> v % 32 is# 0 }) }, | |
\ { -> s:New.find_index(range(1000), { v -> v % 32 is# 0 }) }, | |
\) | |
call s:compare( | |
\ "find\t", | |
\ { -> s:Old.find(range(1000), v:null, { v -> v % 32 is# 0 }) }, | |
\ { -> s:New.find(range(1000), { v -> v % 32 is# 0 }) }, | |
\) | |
call s:compare( | |
\ "take_while", | |
\ { -> s:Old.take_while({ v -> v % 32 is# 0 }, range(1000)) }, | |
\ { -> s:New.take_while(range(1000), { v -> v % 32 is# 0 }) }, | |
\) | |
call s:compare( | |
\ "drop_while", | |
\ { -> s:Old.drop_while({ v -> v % 32 is# 0 }, range(1000)) }, | |
\ { -> s:New.drop_while(range(1000), { v -> v % 32 is# 0 }) }, | |
\) | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment