[問題] clock()一問(已解
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
dev c++
問題(Question):
clock的單位??
程式碼(Code):(請善用置底文網頁, 記得排版)
一個簡單的insertion sort
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
template <class T>
void InsertionSort(T x[],int length)
{
int i,j;
int size=length;
for (i=1;i<size;i++){
T tmp=x[i];
for (j=i-1;j>=0&&tmp>x[j];j--){
x[j+1]=x[j];
}
x[j+1]=tmp;
}
}
void random(int* array,int num)
{
srand(time(0));
for (int i=0;i<num;i++){
array[i]=rand()%num;
}
}
int main(){
clock_t c_start, c_end;
double c_duration=0;
int first[1000];
random(first,1000);
c_start;
InsertionSort(first,1000);
c_end;
c_duration =c_end-c_start;
cout << "所用時間:" << endl;
cout << c_duration/CLK_TCK << "秒" << endl;
cout << endl;
當只做一次的時候 秒數是0.047秒 但是做一萬次的時候 秒數顯示是470秒
問題是電腦才跑11秒就跑完了 不知道哪裡有問題
補充說明(Supplement):
以前曾經寫過 這次又再寫 以前用單核爛電腦 現在用W7 X64 I3
不知道是不是這個原因 問題是我記得記錄是一分鐘可以破10W次計算才是
--
(P)rostitute + (U)nchaste + (M)ammonism + (A)varicious
妓女 淫蕩 拜金 貪婪
PUMA
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 112.105.241.242
※ 編輯: ernieyang09 來自: 112.105.241.242 (10/12 21:34)
→
10/12 21:40, , 1F
10/12 21:40, 1F
→
10/12 21:42, , 2F
10/12 21:42, 2F
找到解答了 c_start=clock(); 我忘記讓他跑了 Orz..
※ 編輯: ernieyang09 來自: 112.105.241.242 (10/12 21:45)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章