⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.hpp

📁 Octane v1.01.20 The Open Compression Toolkit for C++ . The Open Compression Toolkit is a set of mo
💻 HPP
字号:
//
// 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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -