-
-
Notifications
You must be signed in to change notification settings - Fork 331
Expand file tree
/
Copy pathprofile.lua
More file actions
32 lines (27 loc) · 965 Bytes
/
profile.lua
File metadata and controls
32 lines (27 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
local profile = {}
-- bundled version of upstream jit.p until LuaJIT is updated to include
-- https://github.com/LuaJIT/LuaJIT/commit/95140c50010c0557af66dac944403a1a65dd312c
local p = require'plenary.profile.p'
---start profiling using LuaJIT profiler
---@param out name and path of log file
---@param opts table of options
--- flame (bool, default false) write log in flamegraph format
-- (see https://github.com/jonhoo/inferno)
--- popts (string) custom profiler options
function profile.start(out, opts)
out = out or "profile.log"
opts = opts or {}
local popts = opts.popts or "10,i1,s,m0"
if opts.flame then popts = popts .. ",G" end
p.start(popts, out)
end
---stop profiling
profile.stop = p.stop
function profile.benchmark(iterations, f, ...)
local start_time = vim.loop.hrtime()
for _ = 1, iterations do
f(...)
end
return (vim.loop.hrtime() - start_time) / 1E9
end
return profile