Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a long variable name slow performance in r?

For example would the following two run at different speeds if there were in a function that run millions of trials.

the.name.of.a.random.variable.in.r <- some.value

variable <- some.value

Then expanding on this how does this relate to names of functions.

like image 310
Hector Haffenden Avatar asked Jan 03 '23 14:01

Hector Haffenden


1 Answers

My simple benchmarking experiment would indicate that it does not matter:

the.name.of.a.random.variable.in.r <- 1:1000
the.name.of.a.random.variable.in.r.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa <- 1:1000

variable <- 1:1000

microbenchmark::microbenchmark(long=sum(the.name.of.a.random.variable.in.r), 
                               short=sum(variable), 
                               verylong=sum(the.name.of.a.random.variable.in.r.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa))

# Unit: nanoseconds
# expr     min  lq    mean median     uq   max neval cld
# long     970 987 1147.48 1036.5 1057.5 10468   100   a
# short    969 985 1038.82 1030.5 1053.5  1841   100   a
# verylong 968 988 1070.16 1036.0 1062.5  3961   100   a
like image 66
emilliman5 Avatar answered Jan 05 '23 04:01

emilliman5