## In{s}a(ne)!!

**H**aving missed the earliest entry by Radford last month, due to disconnection in Yosemite, I was stunned to read his three entries of the past month about R performances being significantly modify when changing brackets with curly brackets! I (obviously!) checked on my own machine and found indeed the changes in system.time uncovered by Radford… The worst is that I have a tendency to use redundant brackets to separate entities in long expressions and thus make them more readable (I know, this is debatable!), so each new parenthesis add to the wasted time… Note that it is the same with curly bracket: any extra curly bracket takes some additional computing time…

> f=function(n) for (i in 1:n) x=1/(1+x)

> g=function(n) for (i in 1:n) x=(1/(1+x))

> h=function(n) for (i in 1:n) x=(1+x)^(-1)

> j=function(n) for (i in 1:n) x={1/{1+x}}

> k=function(n) for (i in 1:n) x=1/{1+x}

> x=1

> system.time(f(10^6))

user system elapsed

1.684 0.020 1.705

> system.time(g(10^6))

user system elapsed

1.964 0.012 1.976

> system.time(h(10^6))

user system elapsed

2.452 0.016 2.470

> system.time(j(10^6))

user system elapsed

1.716 0.008 1.725

> system.time(k(10^6))

user system elapsed

1.532 0.016 1.548

**I**n the latest of his posts, Radford lists a series of 14 patches that speed up R up to 25%… That R can face such absurdities is pretty annoying! Given that I am currently fighting testing an ABC algorithm with MCMC inner runs, which takes forever to run, this is even depressing!!! As Radford stresses, “slow speed is a significant impediment to greater use of R, much more so than lack of some wish list of new features.”

June 21, 2012 at 2:08 pm

[...] In{s}a(ne)!!: another post about how the use of brackets influence the speed of your code [...]

June 21, 2012 at 12:25 pm

[...] In{s}a(ne)!!: another post about how the use of brackets influence the speed of your code [...]