#include <iostream>
#include <ctime>
int main() {
clock_t start, end;
start = clock();
// 執行需要計時的代碼
end = clock();
double duration = double(end - start) / CLOCKS_PER_SEC;
std::cout << "程序運行時間:" << duration << "秒" << std::endl;
return 0;
}
#include <iostream>
#include <ctime>
void func() {
clock_t start, end;
start = clock();
// 執行需要計時的代碼
end = clock();
double duration = double(end - start) / CLOCKS_PER_SEC;
std::cout << "函數執行時間:" << duration << "秒" << std::endl;
}
int main() {
func();
return 0;
}
#include <iostream>
#include <ctime>
int main() {
clock_t start, end;
start = clock();
// 執行操作1
end = clock();
double duration1 = double(end - start) / CLOCKS_PER_SEC;
start = clock();
// 執行操作2
end = clock();
double duration2 = double(end - start) / CLOCKS_PER_SEC;
std::cout << "操作1執行時間:" << duration1 << "秒" << std::endl;
std::cout << "操作2執行時間:" << duration2 << "秒" << std::endl;
return 0;
}