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) << '\n';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\n"; }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=$1local y=$2local txt="$3"# Set cursor position on screentput cup $x $yecho "$txt" } while [ : ] doclear# Get the system timenow="$(date +"%r")"# Show main - menu, server name and timeshow 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 somethingcase $usrch in1) 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 doneREFER: 16.3. Time / Date Commands
轉載于:https://www.cnblogs.com/xuanyuanchen/p/5996966.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
- 上一篇: ionic本质
- 下一篇: EconomicIndoor集成测试