zoukankan      html  css  js  c++  java
  • C++ 自动计时

    #include<iostream>
    #include<chrono>
    
    struct Timer
    {
    	std::chrono::time_point<std::chrono::steady_clock>start, end;
    	std::chrono::duration<float>duration;
    
    	Timer()
    	{
    		start = std::chrono::high_resolution_clock::now();
    	}
    
    	~Timer()
    	{
    		end = std::chrono::high_resolution_clock::now();
    		duration = end - start;
    
    		float ms = duration.count() * 1000.0f;
    		std::cout << "Timer took " << ms << " ms" << std::endl;
    	}
    };
    
    void Function()
    {
    	Timer timer;
    	for (int i = 0; i < 100; i++)
    	{
    		std::cout << "hello " << std::endl;
    	}
    }
    
    int main()
    {
    	Function();
    
    	std::cin.get();
    }
    
  • 相关阅读:
    053-157
    053-496
    053-128
    053-167
    053-250
    053-674
    离职申请
    日记


  • 原文地址:https://www.cnblogs.com/chengmf/p/14890935.html
Copyright © 2011-2022 走看看