Created
April 15, 2017 21:05
-
-
Save marcelstoer/16c9f10190e5da9572d626bfec6c72a7 to your computer and use it in GitHub Desktop.
How to measure the execution time of a NodeMCU Lua function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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