Last active
August 29, 2015 14:05
-
-
Save syngan/5b91d1d873da3792ff26 to your computer and use it in GitHub Desktop.
リストと辞書へのランダムアクセス
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:R = vital#of("vital").import("Random") | |
" @param n: length of list/dict | |
" @param m: # of loop | |
function! g:Go(n, m) | |
let list = range(a:n) | |
let a = s:R.shuffle(list) | |
let dict = {} | |
for i in list | |
let dict[i] = i | |
endfor | |
let tl = 0 | |
let td = 0 | |
for i in range(a:m) | |
let T0 = reltime() | |
let num = 0 | |
for i in a | |
let num += list[i] | |
endfor | |
let T1 = reltime() | |
let tl += 1000000*(T1[0]-T0[0])+T1[1]-T0[1] | |
let T0 = reltime() | |
let num2 = 0 | |
for i in a | |
let num2 += dict[i] | |
endfor | |
let T1 = reltime() | |
let td += 1000000*(T1[0]-T0[0])+T1[1]-T0[1] | |
if num != num2 | |
echo "???" | |
endif | |
endfor | |
return printf("len=%6d, loop=%5d, list=%8d, dict=%8d",a:n,a:m,tl,td) | |
endfunction | |
echo g:Go( 30, 50) | |
echo g:Go( 50, 50) | |
echo g:Go( 80, 50) | |
echo g:Go( 90, 50) | |
echo g:Go( 100, 50) | |
echo g:Go( 110, 50) | |
echo g:Go( 120, 50) | |
echo g:Go( 150, 50) | |
echo g:Go( 200, 50) | |
echo g:Go( 500, 50) | |
echo g:Go( 800, 50) | |
echo g:Go( 1000, 50) | |
echo g:Go( 3000, 50) | |
echo g:Go( 5000, 50) | |
echo g:Go( 7000, 50) | |
echo g:Go(10000, 50) |
Author
syngan
commented
Sep 4, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment