Download

lua-sampleprof

A Lua sample profiler

  • Tomo
Code 188 linesC 111Lua 49Makefile 28
Docs 305 wordsText 169Markdown 136
NameModifiedLinesSize
LICENSE 20 lines8% of this folder's lines 1.1 KiB15% of this folder's bytes
Makefile 39 lines15% of this folder's lines 572 B8% of this folder's bytes
README.md 19 lines7% of this folder's lines 919 B13% of this folder's bytes
lsampleprof.c 128 lines49% of this folder's lines 3.3 KiB46% of this folder's bytes
test.lua 56 lines21% of this folder's lines 1.3 KiB18% of this folder's bytes

README.md

sampleprof - Lua Sample Profiling

Sample profiling is a code profiling technique where you randomly stop a program and inspect its current state to learn about it. This approach is faster and less disruptive than observing every line of code as it runs, since observation has overhead. With a reasonable sample size, it's easy to get a clear picture of which parts of the codebase are taking up most of the time, while allowing the code to run almost unaffected.

Preview

Usage

The Lua library returns a single function, which takes a function to run, performs sample profiling on it, and gives a table of results. The results table is a mapping from "filename.lua:line" to number of samples. By default, samples are propagated up the callstack, with a decay (0.619).

local sample = require('sampleprof')
local profile = sample(fn)