• 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

  • 相关阅读:
    kubernetes安装
    kubernetes介绍
    Nginx——stream模块
    Nginx——文件路径配置
    Nginx——HTTP核心模块
    Nginx优化性能配置项
    Nginx----运行的配置项
    四十六、进程间通信——管道的分类与读写
    四十五、进程间通信——介绍
    四十四、Linux 线程——线程同步之死锁以及线程和信号
  • 原文地址:https://www.cnblogs.com/xuanyuanchen/p/5996966.html
Copyright © 2020-2023  润新知