Query

This is a discussion on Query within the C Programming forums, part of the General Programming Boards category; pls answere this, which of the following takes less cpu time? 1. for(i=0;i<1000;i++) for(j=0;j<100;j++) x=y; 2. for(j=0;j<100;j++) for(i=0;i<1000;i++) x=y;...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    1

    Query

    pls answere this,

    which of the following takes less cpu time?

    1.

    for(i=0;i<1000;i++)
    for(j=0;j<100;j++)
    x=y;


    2.
    for(j=0;j<100;j++)
    for(i=0;i<1000;i++)
    x=y;

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Why don't you time it and see? It looks like a pretty useless algorithm to me...
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Looks like it would take the same amount of time to me.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>which of the following takes less cpu time?
    Work it out for yourself, or rather should I say, let your computer work it out for you.
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    Or if you have it:
    http://www.rt.com/man/time.1.html
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple query language
    By afflictedd2 in forum C++ Programming
    Replies: 3
    Last Post: 12-04-2008, 04:29 PM
  2. query problem
    By arian in forum C# Programming
    Replies: 1
    Last Post: 08-18-2008, 01:49 PM
  3. DNS Query
    By Simpsonia in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-24-2006, 12:42 AM
  4. dns query
    By bulldog in forum C Programming
    Replies: 6
    Last Post: 02-24-2004, 09:44 AM
  5. WBEM Query too slow
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 10-08-2001, 05:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21