---
title: "Benchmarks"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Benchmarks}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
    collapse = TRUE,
    comment = "#>"
)
```

```{r setup_pkgs}
library(ComplexHeatmap)
library(pheatmap)
library(gplots)
library(ggalign)
```

```{r setup_data}
set.seed(123)
n <- 1000
mat <- matrix(rnorm(n * n), nrow = n)
```

# Compared with other packages
A simple heatmap.
```{r}
bench::mark(
    "heatmap()" = {
        pdf(NULL)
        heatmap(mat, Rowv = NA, Colv = NA)
        dev.off()
        NULL
    },
    "gplots::heatmap.2()" = {
        pdf(NULL)
        heatmap.2(mat, dendrogram = "none", trace = "none")
        dev.off()
        NULL
    },
    "ComplexHeatmap::Heatmap()" = {
        pdf(NULL)
        draw(Heatmap(mat,
            cluster_rows = FALSE, cluster_columns = FALSE,
            use_raster = TRUE
        ))
        dev.off()
        NULL
    },
    "pheatmap::pheatmap()" = {
        pdf(NULL)
        pheatmap(mat, cluster_rows = FALSE, cluster_cols = FALSE)
        dev.off()
        NULL
    },
    "ggalign()" = {
        pdf(NULL)
        print(ggheatmap(mat, filling = "raster"))
        dev.off()
        NULL
    },
    memory = FALSE
)
```

For heatmap with dendrogram
```{r}
bench::mark(
    "heatmap()" = {
        pdf(NULL)
        heatmap(mat)
        dev.off()
        NULL
    },
    "gplots::heatmap.2()" = {
        pdf(NULL)
        heatmap.2(mat, trace = "none")
        dev.off()
        NULL
    },
    "ComplexHeatmap::Heatmap()" = {
        pdf(NULL)
        draw(Heatmap(mat,
            row_dend_reorder = FALSE, column_dend_reorder = FALSE,
            use_raster = TRUE
        ))
        dev.off()
        NULL
    },
    "pheatmap::pheatmap()" = {
        pdf(NULL)
        pheatmap(mat)
        dev.off()
        NULL
    },
    "ggalign()" = {
        pdf(NULL)
        print(ggheatmap(mat, filling = "raster") +
            anno_top() + align_dendro() +
            anno_right() + align_dendro())
        dev.off()
        NULL
    },
    memory = FALSE
)
```
