--[[
---------------------------------------------------------------------------
Remote Train Control Program for Windows

© Copyright 2019 by Mark DiVecchio

	This file is part of Remote Train Control.

	Remote Train Control is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Remote Train Control is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Remote Train Control.  If not, see <http://www.gnu.org/licenses/>.

 Home Page : http://www.silogic.com/trains/RTC_Running.html
---------------------------------------------------------------------------]]
-- Semicolons are not required in Lua code

title = "Performance Counter Test"
--
-- times depends on garbage collection
--
--[[---------------------------------------------------------------------------------------]]
function setup(Engine, TIU)
	LastTime = MicroSeconds();
	ErrorCount = 0;
	Accuracy = 0.0175;	-- in Seconds (approx 1.75%
	return true;		-- false=setup failed, true=setup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
function loop(Engine, TIU)
	-- Always call Sleep() at least once in this function since it returns true;
	Sleep(1.000);
	now = MicroSeconds();
	delta = (now - LastTime)/1000000.0;
	print("Performance Counter = " .. now .. " delta = " .. delta .. "seconds");
	if ((delta - 1.0) > Accuracy) then
		ErrorCount = ErrorCount +1;
		print("Error: delta seconds too Large");
		end;
	LastTime = MicroSeconds();
	return true;	-- false=do not loop, true=continue to loop
	end
--[[---------------------------------------------------------------------------------------]]
function cleanup(Engine, TIU)
	if (ErrorCount == 0) then
		print("No Errors");
		else
		print(ErrorCount .. " Errors");
		end;
	return true;		-- false=cleanup failed, true=cleanup succeeded
	end
--[[---------------------------------------------------------------------------------------]]

