time = {} function profile(func, name) return function() local start = os.clock() local result = {func(...)} local end_ = os.clock() local elasped = end_ - start time[name] = time[name] and time[name] + elasped or elasped return unpack(result) end end function func(n) print("output from func") for i = 1, n, 1 do -- do nothing end end func = profile(func, "func") func(9999999) print(time.func)