Last active
August 29, 2015 13:57
-
-
Save UncleBill/9482014 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
fun! s:use_eval(co) | |
let c = a:co | |
let r = eval('0x'.c[0].c[1]) | |
let g = eval('0x'.c[2].c[3]) | |
let b = eval('0x'.c[4].c[5]) | |
return [r,g,b] | |
endfunction | |
fun! s:without_eval(co) | |
let c = a:co | |
let r = str2nr(c[0:1],16) | |
let g = str2nr(c[2:3],16) | |
let b = str2nr(c[4:],16) | |
return [r,g,b] | |
endf | |
function! s:nr2hex(nr) | |
let n = a:nr | |
let r = "" | |
while n | |
let r = '0123456789ABCDEF'[n % 16] . r | |
let n = n / 16 | |
endwhile | |
return r | |
endfunction | |
let start = reltime() | |
for i in range(0x100) | |
" let color = ( '000000'.s:nr2hex(i) )[-6:] | |
let color = repeat( ('00'.s:nr2hex(i))[-2:], 3 ) | |
let l1 = s:use_eval(color) | |
let l2 = s:without_eval(color) | |
if l1 != l2 | |
echo "Failed at: ".i | |
endif | |
endfor | |
echo "time cost".reltimestr(reltime(start)) | |
echo "All pasted!" |
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 color = '012345' | |
let times = 1000 | |
echo "Results:" | |
echo "-----------------------------------------" | |
echo "run: ".times." times" | |
fun! s:use_eval(co) | |
let c = a:co | |
let r = eval('0x'.c[0].c[1]) | |
let g = eval('0x'.c[2].c[3]) | |
let b = eval('0x'.c[4].c[5]) | |
return [r,g,b] | |
endfunction | |
fun! s:without_eval(co) | |
let c = a:co | |
let r = str2nr(c[0:1],16) | |
let g = str2nr(c[2:3],16) | |
let b = str2nr(c[4:],16) | |
return [r,g,b] | |
endf | |
let start = reltime() | |
for i in range(times) | |
call s:use_eval(color) | |
endfor | |
echo 'use eval:'.reltimestr(reltime(start)) | |
let start = reltime() | |
for i in range(times) | |
call s:without_eval(color) | |
endfor | |
echo 'without eval:'.reltimestr(reltime(start)) |
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
Results: | |
----------------------------------------- | |
run: 1000 times | |
use eval: 0.022386 | |
without eval: 0.019251 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment