Skip to content

Instantly share code, notes, and snippets.

@marcelstoer
Created April 15, 2017 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelstoer/16c9f10190e5da9572d626bfec6c72a7 to your computer and use it in GitHub Desktop.
Save marcelstoer/16c9f10190e5da9572d626bfec6c72a7 to your computer and use it in GitHub Desktop.
How to measure the execution time of a NodeMCU Lua function
-- all credits go to http://www.esp8266.com/viewtopic.php?p=64968#p64968
function profile(name)
local start = tmr.now()
_G[name]()
local delta = tmr.now() - start
print(name .. " needs " .. (delta / 1000) .. " ms")
end
function longTime()
local sum = 0
for i = 1, 100000, 1 do
sum = sum + i
end
print(sum)
end
profile("longTime")
-- yields:
-- > 5000050000
-- > longTime needs 474.855 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment