Speed to extract vector element by name with or without returning name: ["x"], [["x"]], [n] or unname()
The speed is higher using [[n]] then [["x"]]. unname(["x"]) is the slowest.
> Growth
alpha beta M S K x0
0.007984356 0.018129643 81.782205061 2.978223538 13.309442413 5.072000000
alpha beta M S K x0
0.007984356 0.018129643 81.782205061 2.978223538 13.309442413 5.072000000
> system.time({for(i in 1:1E6) K <- Growth[[1]]})
user system elapsed
0.035 0.000 0.035
user system elapsed
0.035 0.000 0.035
> system.time({for(i in 1:1E6) K <- Growth[["alpha"]]})
user system elapsed
0.083 0.002 0.086
> system.time({for(i in 1:1E6) K <- Growth[1]})
user system elapsed
0.145 0.004 0.150
> system.time({for(i in 1:1E6) K <- Growth["alpha"]})
user system elapsed
0.150 0.004 0.154
> system.time({for(i in 1:1E6) K <- unname(Growth[1])})user system elapsed
0.083 0.002 0.086
> system.time({for(i in 1:1E6) K <- Growth[1]})
user system elapsed
0.145 0.004 0.150
> system.time({for(i in 1:1E6) K <- Growth["alpha"]})
user system elapsed
0.150 0.004 0.154
user system elapsed
1.122 0.007 1.135
> system.time({for(i in 1:1E6) K <- unname(Growth["alpha"])})
user system elapsed
1.144 0.011 1.158
user system elapsed
1.144 0.011 1.158
Commentaires
Enregistrer un commentaire