Simple benchmarks

Simple benchmarks#

Here, we perform simple benchmarks to demonstrate basic performance.

[1]:
from __future__ import annotations

import scanpy as sc

import anndata as ad
[2]:
adata = sc.datasets.pbmc3k()
[3]:
adata
[3]:
AnnData object with n_obs × n_vars = 2700 × 32738
    var: 'gene_ids'

Reading & writing#

Let us start by writing & reading anndata’s native HDF5 file format: .h5ad:

[4]:
%%time
adata.write("test.h5ad")
CPU times: user 93.9 ms, sys: 17.4 ms, total: 111 ms
Wall time: 118 ms
[5]:
%%time
adata = ad.read_h5ad("test.h5ad")
CPU times: user 51.2 ms, sys: 13.3 ms, total: 64.5 ms
Wall time: 64.1 ms

We see that reading and writing is much faster than for loom files. The efficiency gain here is due to explicit storage of the sparse matrix structure.

[6]:
%%time
adata.write_loom("test.loom")
CPU times: user 2.82 s, sys: 457 ms, total: 3.27 s
Wall time: 3.31 s
[7]:
%%time
adata = ad.read_loom("test.loom")
CPU times: user 1.05 s, sys: 221 ms, total: 1.28 s
Wall time: 1.28 s
/Users/alexwolf/repos/anndata/anndata/_core/anndata.py:120: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)