Skip to content
Back to skills

Microbenchmark

ASecurity

R microbenchmark package for precise timing. Use for sub-millisecond accurate timing of R expressions.

  • 5 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added June 4, 2026
dataexpress

Security analysis

A100/100

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill microbenchmark --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Microbenchmark?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Microbenchmark
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-microbenchmark/badge)](https://www.skillsdirectory.com/skills/leolin990405-microbenchmark)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: microbenchmark
description: R microbenchmark package for precise timing. Use for sub-millisecond accurate timing of R expressions.
---

# microbenchmark

Accurate timing functions.

## Basic Usage

```r
library(microbenchmark)

# Benchmark expressions
microbenchmark(
  sqrt(x),
  x^0.5,
  exp(log(x)/2)
)
```

## Options

```r
microbenchmark(
  sqrt(x),
  x^0.5,
  times = 100,           # Number of evaluations
  unit = "ms",           # Time unit
  check = "equal",       # Check results equal
  control = list(
    order = "random",    # Randomize order
    warmup = 10          # Warmup iterations
  )
)
```

## Named Expressions

```r
microbenchmark(
  "sqrt" = sqrt(x),
  "power" = x^0.5,
  "exp_log" = exp(log(x)/2)
)
```

## Setup Code

```r
microbenchmark(
  sort(x),
  order(x),
  setup = {
    x <- runif(1000)
  }
)
```

## Results

```r
results <- microbenchmark(
  sqrt(x),
  x^0.5
)

# Summary
summary(results)

# As data frame
as.data.frame(results)

# Print with unit
print(results, unit = "ms")
```

## Plotting

```r
# Autoplot (requires ggplot2)
library(ggplot2)
autoplot(results)

# Boxplot
boxplot(results)

# Violin plot
autoplot(results) +
  geom_violin()
```

## Compare Functions

```r
# Compare implementations
f1 <- function(x) sum(x)
f2 <- function(x) Reduce(`+`, x)

x <- 1:1000
microbenchmark(
  f1(x),
  f2(x)
)
```

## Time Units

```r
# Available units
# "ns" - nanoseconds
# "us" - microseconds
# "ms" - milliseconds
# "s"  - seconds

print(results, unit = "relative")  # Relative to fastest
```

## Statistical Summary

```r
results <- microbenchmark(expr1, expr2)

# Access statistics
summary(results)$min
summary(results)$mean
summary(results)$median
summary(results)$max
summary(results)$neval
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.