Readability vs speed in R
I have bad news for those of you trying to produce lucid code!
In his blog Radford M. Neal, Professor at the University of Toronto, published an article with the headline Two Surprising Things about R. He worked out, that parentheses in mathematical expression slow down the run-time dramatically! In contrast it seems to be less time consuming to use curly brackets. I verified these circumstances to be true:
As you can see adding extra parentheses is not really intelligent concerning run-time, and not in a negligible way. This fact shocked me, because I always tried to group expressions to increase the readability of my code! Using curly brackets speeds up the execution in comparison to parentheses. Both observations are also surprising to me! So the conclusion is: Try to avoid redundant parentheses and/or brackets!
To learn more about the why you are referred to his article. He also found a interesting observation about squares. In a further article he presents some patches to speed up R.
Leave a comment
There are multiple options to leave a comment:
- send me an email
- submit a comment through the feedback page (anonymously via TOR)
- Fork this repo at GitHub, add your comment to the _data/comments directory and send me a pull request
- Fill the following form and Staticman will automagically create a pull request for you:
2 comments
[…] Puede verse más información sobre el mismo tema aquí, aquí y aquí. […]
Nice post. I don’t know that I find extra parantheses or grouping increases readability though. Why not just use more whitespace instead to increase readability?