<%@include file="includes/setup.md.rsp"%>

<%@string fcnname="binMeans"%>
<%@string subname="binMeans"%>
<%@meta title="${subname}() benchmarks on subsetted computation"%>
<%@meta author="Dongcan Jiang"%>
<%@meta date="2014-06-05"%>

<%@include file="${header}"%>


# <%@meta name="title"%>

This report benchmark the performance of <%=subname%>() on subsetted computation.


## Results

### Non-sorted simulated data
```r
<%=withCapture({
nx <- 100e3 # Number of data points
set.seed(0xBEEF)
x <- runif(nx, min = 0, max = 1)
y <- runif(nx, min = 0, max = 1)

# Uniformely distributed bins
nb <- 1e3 # Number of bins
bx <- seq(from = 0, to = 1, length.out = nb+1L)
bx <- c(-1, bx, 2)

# indices for subsetting
idxs <- sample.int(length(x), size = length(x)*0.7)
})%>
```

<% benchmark <- function() { %>
<% dataLabel <- if (is.unsorted(x)) "unsorted" else "sorted" %>
<% message(dataLabel) %>
```r
<%=withCapture({
x_S <- x[idxs]
y_S <- y[idxs]
gc()

stats <- microbenchmark(
 "binMeans_x_y_S"            = binMeans(x = x_S, y = y_S, bx = bx, count = TRUE),
 "binMeans(x, y, idxs)"        = binMeans(x = x, y = y, idxs = idxs, bx = bx, count = TRUE),
 "binMeans(x[idxs], y[idxs])" = binMeans(x = x[idxs], y = y[idxs], bx = bx, count = TRUE),
 unit = "ms"
)
})%>
```

<% benchmarkResults(stats, tags=dataLabel) %>
<% } # benchmark() %>

<% benchmark() %>


### Sorted simulated data
```r
<%=withCapture({
  x <- sort(x)
  idxs <- sort(idxs)
})%>
```
<% benchmark() %>


<%@include file="${footer}"%>


<%---------------------------------------------------------------------------
HISTORY:
2014-06-05
o Created.
---------------------------------------------------------------------------%>
