1. R语言运行效率分析_小结(6)

小结(6)

本节把前面全部数据综合起来进行分析。1000<n<1000000。java

数据格式与前面的同样。如下是做图代码。在本图中,因为数据的数量级差有些大,因此用对数坐标画图。函数

library(tidyverse)
library(scales)
ggplot(data[which(data$fun!="ddply_parallel"),],aes(n,mean,color=fun))+
  geom_point()+
  facet_wrap(~type,ncol=1)+
  theme(axis.text.x   = element_text(angle=90))+
  scale_x_continuous(name="length of vector", 
                     trans = log10_trans(),
                     breaks = trans_breaks("log10", function(x) 10^x),
                     labels = trans_format("log10", math_format(10^.x)))+
  scale_y_continuous(name="time (microsecond)",
                     trans = log10_trans(),
                     breaks = trans_breaks("log10", function(x) 10^x),
                     labels = trans_format("log10", math_format(10^.x)))+
  coord_flip()

在这里插入图片描述
在这里插入图片描述在这里插入图片描述从上图能够看出,对于All,Month或Season来讲,这8个函数中,随着数据量的增长,ddply,join,str_replace和which处理单个数据所需时间急速降低,随着数据量的继续增长,ddply 在n=10000时有一个明显的拐点。对于for_if,for_if_else,for_ifelse和for_switch来讲,随数据量的增长,处理每一个数据所需时间变化相对较小,而且没有明显的拐点。所以,在处理数据量小于10000的时候,选择哪一个函数区别不是很明显,但当数据量大于100000,最好选择which和join函数。另外,对于for系列函数,随数据量的增长,每一个数据处理平均时间变化比较平稳。spa

截止目前,除了并行运算,其它函数的运行效率已基本总结完毕。3d

这个专题暂告一段落。有空再续……code

相关文章
相关标签/搜索