zoukankan      html  css  js  c++  java
  • time 函数

    1、Python Time

    2、C++ Time

    Example:

    #include <iostream>
    #include <chrono> //C++的`计时`库
    #include <ctime>
     
    long fibonacci(unsigned n)
    {
        if (n < 2) return n;
        return fibonacci(n-1) + fibonacci(n-2);
    }
     
    int main()
    {
        std::chrono::time_point<std::chrono::system_clock> start, end;
        start = std::chrono::system_clock::now();
        std::cout << "f(42) = " << fibonacci(42) << '
    ';
        end = std::chrono::system_clock::now();
     
        std::chrono::duration<double> elapsed_seconds = end-start;
        std::time_t end_time = std::chrono::system_clock::to_time_t(end);
     
        std::cout << "finished computation at " << std::ctime(&end_time)
                  << "elapsed time: " << elapsed_seconds.count() << "s
    ";
    }
    
    
    

    3、C语言 time

    4、Shell time

    注意:now=$(date +"%T"),这里是T,不是I

    #!/bin/bash
    # Purpose: Demo date command and menus 
    # Author: nixCraft <www.cyberciti.biz> under GPL v2.x+
    # ------------------------------------------------------
     
    # Display text at given row and column 
    show(){
            local x=$1
            local y=$2
            local txt="$3"
            # Set cursor position on screen
            tput cup $x $y
            echo "$txt"
    }
    while [ : ]
    do
            clear
            # Get the system time
            now="$(date +"%r")"
            # Show main - menu, server name and time
            show 10 10 "MAIN MENU for $HOSTNAME - $now"
            show 11 10 "1. System info"
            show 12 10 "2. Apache server stats"
            show 13 10 "3. MySQL server stats"
            show 14 10 "4. Firewall stats"
            show 15 10 "5. Exit"
            tput cup 16 10; read -t 2 -p "Choice [1-5] ? " usrch
            # do something
            case $usrch in
                    1) read -t 2 -p "Showing system info, wait..." fakeinput;;
                    2) read -t 2 -p "Showing apache info, wait..." fakeinput;;
                    3) read -t 2 -p "Showing mysqld info, wait..." fakeinput;;
                    4) read -t 2 -p "Showing firewall info, wait..." fakeinput;;
                    5) echo "Bye."; exit 0;;
            esac
    done
    
    

    REFER: 16.3. Time / Date Commands

  • 相关阅读:
    C++中的动态内存管理
    Harbor镜像仓库搭建
    nexus私服搭建
    Tekton ACK安装
    容器监控实践,从入门到放弃
    Bitwarden_搭建密码服务器
    Jenkins-部署文档
    Mysql-基本的
    Zabbix添加-钉钉故障报警
    ZABBIX-4.4 yum安装
  • 原文地址:https://www.cnblogs.com/xuanyuanchen/p/5996966.html
Copyright © 2011-2022 走看看