CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2008
    Posts
    1

    Unhappy 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

  2. #2
    Join Date
    Jun 2005
    Posts
    1,255

    Smile 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
  •  





Click Here to Expand Forum to Full Width

Featured