AgentSkillsCN

r-benchmarking

R 语言基准测试、性能剖析与性能分析,兼具可重复性与严谨的测量标准。当您需要计时 R 代码的执行时间、使用 Rprof 或 profvis 进行性能剖析、测量内存分配、比较函数性能,或优化性能瓶颈时——例如,“对 R 函数进行基准测试”、“profvis 性能剖析”、“microbenchmark 性能对比”、“性能分析”、“内存性能剖析”——此技能将助您事半功倍。

SKILL.md
--- frontmatter
name: r-benchmarking
description: |
  R benchmarking, profiling, and performance analysis with reproducibility and measurement rigor. Use when timing R code execution, profiling with Rprof or profvis, measuring memory allocations, comparing function performance, or optimizing bottlenecks—e.g., "benchmark R function", "profvis profiling", "microbenchmark comparison", "performance analysis", "memory profiling".

R Benchmarking Skill

Purpose

Produce production-grade R benchmarking guidance and code with reproducibility and measurement rigor. We're building measurements we can trust—selecting the right tool (base timing vs microbench vs profiling) and explaining why this choice matters.

References (Load on Demand)

Decision Guide

GoalToolNotes
Macro timing (end-to-end)system.time() or proc.time()Simple, no dependencies
Microbenchmarks + allocationsbench::mark()Preferred; use bench::press() for parameter grids
Legacy/simple comparisonsmicrobenchmark or rbenchmark::benchmark()When bench not available
Profiling hotspotsRprof() + summaryRprof()Use profvis() for interactive exploration
Script instrumentationtictoc::tic()/toc()Nested timing checkpoints

Workflow

BEFORE PROCEEDING, clarify your goal. This determines everything that follows.

  1. Announce your goal (macro timing vs microbench vs profiling). Infer from context if not explicit; state your assumption explicitly.
  2. Immediately apply reproducibility rules (inputs, seed, environment details, warmup). Measurement without reproducibility is noise.
  3. Provide minimal, correct code snippet with the right tool and key parameters.
  4. Explain how to interpret outputs (time, itr/sec, mem_alloc, gc/sec, by.self/by.total).
  5. Call out pitfalls (I/O, GC, elapsed vs CPU, too-short sampling intervals).

Output Contract

You MUST provide all of the following without exception:

  • Tool choice and rationale—explain why this tool, why now
  • R code snippet with key parameters configured correctly
  • Notes on interpretation and pitfalls—what will mislead you

For profiling: include how to summarize and visualize results. Missing this wastes the profiling effort.

For microbenchmarks: include guidance on iterations, GC filtering, and result equivalence checks. Ignoring GC effects produces misleading rankings.

Quality Standards

  • YOU MUST use bench::mark() for microbenchmarks unless user explicitly requires legacy tools
  • NEVER recommend single-run timings for comparisons—this produces garbage results without exception
  • ALWAYS cite reference documentation directly—guessing APIs leads to silent failures