//
// Simple class for timing code (low resolution).
//
// Copyright (c) 2003 by Octane Project Group
// All Rights Reserved
//
// http://octane.sourceforge.net/
//

/// @file   timer.hpp
/// @brief  Simple class for timing code (low resolution).
/// @author Jibz
/// @date   2003.07.30

#ifndef OCTANE_TIMER_HPP_INCLUDED
#define OCTANE_TIMER_HPP_INCLUDED

#include <ctime>

// use namespace for clock and clock_t which should be in std::
// namespace but visual c++ 6 compatibility means we cant
// explicitly refer to std::clock_t.
using namespace std;

/// Simple class for timing code (low resolution).
///
/// The timer class uses the clock() function from the C
/// standard library.
///
/// @ingroup Utility
///
class OctaneTimer {

public:
    /// Constructor. Sets the begin time to the current time.
    OctaneTimer() : begin(clock()), elapsed(0.0) { ; }

    /// Reset the begin time to the current time.
    void start() { begin = clock(); }

    /// Compute the elapsed time between the begin time and the
    /// current time.
    /// @return elapsed time.
    float stop()
    {
	clock_t end = clock();
	elapsed = (float)(end - begin)/(float)CLOCKS_PER_SEC;
	return elapsed;
    }

    /// Get the elapsed time between the last start() and the
    /// latest stop().
    /// @return elapsed time.
    float get_elapsed() const { return elapsed; }

private:
    clock_t begin;
    float elapsed;
};

#endif // OCTANE_TIMER_HPP_INCLUDED
