R & C++ integration

这题目太标题党了,最近啃了半部《C++ Primer Plus》,除了书中习题,就没其它写过C++程序,下午读了Rcpp的文档,把mlass包里kMeans算法的核心部分用c++重新写了。

C++果然给力,速度提高不是一点两点。

> require(mlass)
> data(iris)
> x=iris[,-5]
> res = benchmark(kMeans(x, 3, lang="CPP"), 
+ kMeans(x, 3, lang="R"), 
+ columns=c("test", "replications", "elapsed", 
+ "relative", "user.self", "sys.self"))
> res
                        test replications elapsed relative user.self sys.self
1 kMeans(x, 3, lang = "CPP")          100   0.176  1.00000     0.173    0.003
2   kMeans(x, 3, lang = "R")          100  11.343 64.44886    11.293    0.015
p5rn7vb

Related Posts

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>