Skip to content

Commit 5d556bf

Browse files
committed
compare to std::accumulate
1 parent 57faf42 commit 5d556bf

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

examples/boost-simd-accumulate.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ struct plus
1717
// [[Rcpp::export]]
1818
double simd_sum(NumericVector x)
1919
{
20-
return boost::simd::accumulate(
21-
x.begin(),
22-
x.end(),
23-
0.0,
24-
plus()
25-
);
20+
return boost::simd::accumulate(x.begin(), x.end(), 0.0, plus());
21+
}
22+
23+
// [[Rcpp::export]]
24+
double cpp_sum(NumericVector x)
25+
{
26+
return std::accumulate(x.begin(), x.end(), 0.0, plus());
2627
}
2728

2829
/***R
2930
n <- 1024 * 1000
3031
data <- rnorm(n)
3132
simd_sum(data)
32-
microbenchmark(R = sum(data), simd = simd_sum(data))
33-
*/
33+
microbenchmark::microbenchmark(
34+
R = sum(data),
35+
simd = simd_sum(data),
36+
cpp = cpp_sum(data)
37+
)
38+
*/

0 commit comments

Comments
 (0)