-
October 31st, 2008, 04:52 AM
#1
About Process Time
I tried a nested looping and found a weird question. I hope some expert can help me solve it. Here is my code
Code:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
for(int i=0; i<50000; i++)
{
int a[] = {0,0,0,0,0,0,0,0,0,0};
int b[] = {0,0,0,0,0,0,0,0,0,0};
for(int j=0; j<10; j++)
{
b[j] = int(10 * rand() / (RAND_MAX + 1));
a[b[j]]++;
}
}
cout << "Time spend: " << clock() << "\n";
system("pause");
return 0;
}
Code:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
for(int i=0; i<50000; i++)
{
int a[] = {0,0,0,0,0,0,0,0,0,0};
int b[] = {0,0,0,0,0,0,0,0,0,0};
for(int j=0; j<10; j++)
b[j] = int(10 * rand() / (RAND_MAX + 1));
for(int j=0; j<10; j++)
a[b[j]]++;
}
cout << "Time spend: " << clock() << "\n";
system("pause");
return 0;
}
After these processes the time spend show me twice for loop will faster than single process. I'm very confuse of this process
-
October 31st, 2008, 07:49 AM
#2
Re: About Process Time
Sorry, I'm confused about your sentence: "After these processes the time spend show me twice for loop will faster than single process."I have no idea what you meant, but I would bet two GM shares that the second program is faster, because loops are not very time consuming when they contain a short line instead of a big paragraph.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|