Skip to content
All library documents

Benchmarking Pine Script Execution Time and Variability

Article TradingView scripts

Summary

This Pine library provides a framework for measuring the runtime of Pine Script calculations and comparing segments of a script. A benchmark can collect a configured number of samples, run each tested segment repeatedly, and place marks between segments. It reports timing summaries including mean, minimum, maximum, standard deviation, relative variability, throughput, and change between successive samples.

The examples demonstrate repeated loop-based tests and a simpler per-bar approach for computationally expensive work. The library also includes state checks and errors for incomplete runs or mismatched sample counts, and a reference helper intended to prevent the compiler from optimizing away the tested calculation. It is a developer tool rather than a trading signal or performance study: it measures script execution behavior, not strategy returns. Results depend on the benchmark design and workload, and its own notes flag a limitation around processing complete spans when intervals are used.

Key ideas

  • The library measures elapsed time for repeated Pine Script code segments.
  • Samples can repeat a workload through loops and record boundaries with marks.
  • Reports include central tendency, spread, extrema, throughput, and timing change across samples.
  • State validation catches unfinished benchmarks and discrepancies between requested and captured samples.
  • Benchmarks measure code runtime rather than trading performance, and workload design affects interpretation.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.