using System;
using Microsoft.SPOT;

using Microsoft.SPOT.Hardware;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using CPF;

using System.Text;
using System.Threading;
using HWModules;
using SWModules;
using CPF.Surface_States;
using CPF.Profile_States;

namespace CPFUnitTests
{
    class DateTimeSpeedTest
    {
        private static DateTime timeNow;
        private static DateTime lastTime;
        private static TimeSpan testTS = new TimeSpan(0, 0, 60);

        private static StringBuilder sbTemp = new StringBuilder(128);

        [TestMethod]
        public void TestDateTimeSpeed()
        {
            Debug.Print("starting loop");
            tic();
            for (int i = 0; i < 100; i++)
            {
                timeNow = DateTime.Now;
                if ((timeNow - lastTime) > testTS)
                {
                    Debug.Print("Timed out");
                    lastTime = timeNow;
                }
            }
            toc();

        }

        private static TimeSpan startTic = new TimeSpan();

        public static void tic()
        {
            startTic = Utility.GetMachineTime(); ;
        }

        private static TimeSpan endToc = new TimeSpan();
        private static TimeSpan timeDiff = new TimeSpan();
        private static int elapsedMilliseconds;

        public static void toc()
        {
            endToc = Utility.GetMachineTime();

            timeDiff = endToc - startTic;
            elapsedMilliseconds = (timeDiff.Days * 24 * 3600 * 1000) + (timeDiff.Hours * 3600 * 1000) + (timeDiff.Seconds * 1000) + timeDiff.Milliseconds;

            sbTemp.Clear();
            sbTemp.Append("Elapsed time (mSec) = ");
            sbTemp.Append(elapsedMilliseconds.ToString());
            //Debug.Print(sbTemp.ToString());
        }
    }
}
