demo<- function(n){
test<- 1:n
for(i in length(test)){
test[i]=log(test[i])
}
return(test)
}
用cmpfun函數把它轉成位元碼
> democmp<- compiler::cmpfun(demo)
先來做個十萬筆來比較看看有沒有變快
> system.time(a<- demo(100000)) user system elapsed 0.142 0.000 0.140 > system.time(a<- democmp(100000)) user system elapsed 0.025 0.000 0.024
現在我們把處裡的資料從十萬筆慢慢拉大到一百萬試試看!
經過
沒有留言:
張貼留言