timer.h

来自「利用C」· C头文件 代码 · 共 64 行

H
64
字号
// Copyright (C) 2008 Anders Logg.// Licensed under the GNU LGPL Version 2.1.//// First added:  2008-06-13// Last changed: 2008-06-13#ifndef __TIMER_H#define __TIMER_H#include <dolfin/log/LogManager.h>#include "timing.h"namespace dolfin{  /// A timer can be used for timing tasks. The basic usage is  ///  ///   Timer timer("Assembling over cells");  ///  /// The timer is started at construction and timing ends  /// when the timer is destroyed (goes out of scope). It is  /// also possible to start and stop a timer explicitly by  ///  ///   timer.start();  ///   timer.stop();  ///  /// Timings are stored globally and a summary may be printed  /// by calling  ///  ///   summary();  class Timer  {  public:    /// Create timer    Timer(std::string task) : task(task), t(time()), stopped(false) {}    /// Destructor    ~Timer() { if (!stopped) stop(); }    /// Start timer    inline void start() { t = time(); stopped = false; }        /// Stop timer    void stop() { LogManager::logger.timing(task, time() - t); stopped = true; }  private:    // Name of task    std::string task;    // Start time    real t;    // True if timer has been stopped    bool stopped;  };}#endif

⌨️ 快捷键说明

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