Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. how long does it take

how long does it take

Scheduled Pinned Locked Moved The Lounge
question
33 Posts 17 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y yassir hannoun

    how long does it take for a computer to count from 0 to the maximum value of int ??

    realJSOPR Offline
    realJSOPR Offline
    realJSOP
    wrote on last edited by
    #15

    You can't do that on Vista unless you have SP1 because Vista never finishes calculating how long it's going to take.

    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
    -----
    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

    P 1 Reply Last reply
    0
    • P Pete OHanlon

      Release, Debug or Plain English?

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      M Offline
      M Offline
      martin_hughes
      wrote on last edited by
      #16

      Pete O'Hanlon wrote:

      Plain English

      Shhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh!

      P 1 Reply Last reply
      0
      • realJSOPR realJSOP

        You can't do that on Vista unless you have SP1 because Vista never finishes calculating how long it's going to take.

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #17

        On Vista, the answer is "2 seconds remaining." and remains that way till the Sun shrinks to the size of a lump of coal.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        M 1 Reply Last reply
        0
        • G Gary Kirkham

          But unless the loop writes something then how do you know the computer is counting...it could be skipping the loop altogether and laughing at you behind your back.

          Gary Kirkham Forever Forgiven and Alive in the Spirit The fool has said in his heart, "There is no God" Me blog, You read

          M Offline
          M Offline
          martin_hughes
          wrote on last edited by
          #18

          :laugh: Mine does this all the time - lousy computer!

          1 Reply Last reply
          0
          • M martin_hughes

            Pete O'Hanlon wrote:

            Plain English

            Shhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh!

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #19

            It's like Candyman. If you say Plain English 3 times, up pops Osmo.

            Deja View - the feeling that you've seen this post before.

            My blog | My articles

            M 1 Reply Last reply
            0
            • P Pete OHanlon

              On Vista, the answer is "2 seconds remaining." and remains that way till the Sun shrinks to the size of a lump of coal.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              M Offline
              M Offline
              martin_hughes
              wrote on last edited by
              #20

              Nonsense - Vista recognises such an operation as a security risk, prompts the user for administrative access and then refuses to run the task regardless :)

              Y 1 Reply Last reply
              0
              • P Pete OHanlon

                OK - I just ran it and it took 8 seconds.

                static void Main(string[] args)
                {
                Console.WriteLine(DateTime.Now.ToString());
                for (int i = 0; i < int.MaxValue; i++)
                {
                if (i == int.MaxValue - 2)
                {
                Console.WriteLine("Hi");
                }
                }
                Console.WriteLine(DateTime.Now.ToString());
                Console.ReadLine();
                }

                Two things come to mind - why do you want to do this and do you realise you just asked a programming question in the lounge?

                Deja View - the feeling that you've seen this post before.

                My blog | My articles

                Y Offline
                Y Offline
                yassir hannoun
                wrote on last edited by
                #21

                i m doing it just fo fun :d

                1 Reply Last reply
                0
                • M martin_hughes

                  Nonsense - Vista recognises such an operation as a security risk, prompts the user for administrative access and then refuses to run the task regardless :)

                  Y Offline
                  Y Offline
                  yassir hannoun
                  wrote on last edited by
                  #22

                  doing it under XP Pro SP2

                  M 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    It's like Candyman. If you say Plain English 3 times, up pops Osmo.

                    Deja View - the feeling that you've seen this post before.

                    My blog | My articles

                    M Offline
                    M Offline
                    martin_hughes
                    wrote on last edited by
                    #23

                    Hmmm. I always thought of him as more as a noxious cloud of bum gas: invisible, lingering and stinking up the joint a treat. :)

                    1 Reply Last reply
                    0
                    • Y yassir hannoun

                      how long does it take for a computer to count from 0 to the maximum value of int ??

                      M Offline
                      M Offline
                      Mladen Jankovic
                      wrote on last edited by
                      #24

                      What computer? What language? What compiler? What version of compiler... I guess you’re not interested in result of 16-bit DOS program compiled by compiler with sizeof(int) = 4 that runs in 32-bit protected mode extender inside virtual 16-bit DOS box on 32-bit Windows 98 running on virtual machine run by 32-bit VirtualPC on 64-bit Vista through WoW64? Or maybe you are? :~

                      Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)

                      1 Reply Last reply
                      0
                      • Y yassir hannoun

                        doing it under XP Pro SP2

                        M Offline
                        M Offline
                        martin_hughes
                        wrote on last edited by
                        #25

                        I'm not sure I care.

                        1 Reply Last reply
                        0
                        • P Pete OHanlon

                          OK - I just ran it and it took 8 seconds.

                          static void Main(string[] args)
                          {
                          Console.WriteLine(DateTime.Now.ToString());
                          for (int i = 0; i < int.MaxValue; i++)
                          {
                          if (i == int.MaxValue - 2)
                          {
                          Console.WriteLine("Hi");
                          }
                          }
                          Console.WriteLine(DateTime.Now.ToString());
                          Console.ReadLine();
                          }

                          Two things come to mind - why do you want to do this and do you realise you just asked a programming question in the lounge?

                          Deja View - the feeling that you've seen this post before.

                          My blog | My articles

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #26

                          Pete O'Hanlon wrote:

                          do you realise you just asked a programming question in the lounge?

                          Nah, everyone else turned it into one. He just asked how long a computer takes to count. Cheers, Drew.

                          1 Reply Last reply
                          0
                          • Y yassir hannoun

                            how long does it take for a computer to count from 0 to the maximum value of int ??

                            E Offline
                            E Offline
                            El Corazon
                            wrote on last edited by
                            #27

                            yassir hannoun wrote:

                            how long does it take for a computer to count from 0 to the maximum value of int ??

                            get your stop watch ready! okay.... start.... Now! okay... done... How long was that?

                            _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

                            1 Reply Last reply
                            0
                            • Y yassir hannoun

                              how long does it take for a computer to count from 0 to the maximum value of int ??

                              M Offline
                              M Offline
                              MarkB777
                              wrote on last edited by
                              #28

                              Longer than im willing to sit there waiting... :D

                              Mark Brock Click here to view my blog

                              Y 1 Reply Last reply
                              0
                              • A Anton Afanasyev

                                You have to realize you are slowing it down by A LOT by calling Console.WriteLine(i); In fact, calling ANYTHING inside that loop will slow it down. remove that line, and run again. also, make sure you run it without optimizations turned on, or the optimizer would just strip the forloop out.

                                J Offline
                                J Offline
                                John M Drescher
                                wrote on last edited by
                                #29

                                I believe it should take around or less than 10 seconds on a modern 2GHz processor. My reasoning is that the increment will take 1 clock cycle and the looping should be predicted so that will be like a near jump. I believe that will be less than 4 cycles. So in total less than (or equal to) 5 cycles per loop on a machine that does 2 billion cycles per second...

                                John

                                R 1 Reply Last reply
                                0
                                • M MarkB777

                                  Longer than im willing to sit there waiting... :D

                                  Mark Brock Click here to view my blog

                                  Y Offline
                                  Y Offline
                                  yassir hannoun
                                  wrote on last edited by
                                  #30

                                  with this static void Main(string[] args) { DateTime start = DateTime.Now; for (int i = 0; i < int.MaxValue; i++) { Console.WriteLine(i); } DateTime finish = DateTime.Now; Console.WriteLine("counting started at {0} and finished at {1}", start, finish); } it took more than 10 hours

                                  1 Reply Last reply
                                  0
                                  • Y yassir hannoun

                                    how long does it take for a computer to count from 0 to the maximum value of int ??

                                    M Offline
                                    M Offline
                                    Mike Dimmick
                                    wrote on last edited by
                                    #31

                                    The simplest program I can think of to do this would, in assembler, be along the lines of

                                    xor eax, eax ; set counter to 0
                                    repeat:
                                    inc eax ; increment count
                                    jns repeat ; repeat until count goes negative

                                    taking advantage of the wrapping property, so we just test whether the sign flag is set and if not (indicating a positive integer) we repeat the instruction. On my Core 2 Duo T7200 laptop, this took 1,117 milliseconds. Note that it actually executes 231 times, not 231 - 1. To reduce the cheating effect, I thought I'd try a more advanced feature of the x86 instruction set - you can put a count in a different register and count down. This looks like:

                                    xor eax, eax ; Reset count to 0
                                    mov ecx, 7fffffffh ; Number of times to count
                                    repeat:
                                    inc eax ; Increment count
                                    loop repeat ; go round again

                                    That took 6,654 ms. Out of interest - and because this is a surprisingly large duration - I thought I'd try turning the loop instruction into simpler, more common instructions:

                                        xor eax, eax        ; Reset count to 0
                                        mov ecx, 7fffffffh  ; Number of times to count
                                    

                                    repeat:
                                    inc eax ; Increment count
                                    dec ecx ; Decrement the loop counter
                                    jnz repeat ; go round again

                                    This now hits 1099ms. Full code if you want to do this in C++ and verify it:

                                    void __declspec(naked) DoCount()
                                    {
                                    __asm
                                    {
                                    xor eax, eax ; Reset eax to 0
                                    repeat:
                                    inc eax ; Increment eax
                                    jns repeat ; Repeat until eax is negative
                                    ret ; Done
                                    }
                                    }

                                    void __declspec(naked) DoLoopCount()
                                    {
                                    __asm
                                    {
                                    xor eax, eax ; Reset count to 0
                                    mov ecx, 7fffffffh ; Number of times to count
                                    repeat:
                                    inc eax ; Increment count
                                    loop repeat ; go round again
                                    ret ; Done
                                    }
                                    }

                                    void __declspec(naked) DoCountedLoop()
                                    {
                                    __asm
                                    {
                                    xor eax, eax ; Reset count to 0
                                    mov ecx, 7fffffffh ; Number of times to count
                                    repeat:
                                    inc eax ; Increment count
                                    dec ecx ; Decrement the loop counter
                                    jnz repeat ; go round again
                                    ret ; Done
                                    }
                                    }

                                    void __declspec(naked) NullFunc()
                                    {
                                    __asm ret;
                                    }

                                    typedef void (*PFN)();

                                    void TimeFunction( PFN pfn )
                                    {
                                    LARGE_INTEGER liStart, liEnd, liFreq;

                                    Qu
                                    
                                    1 Reply Last reply
                                    0
                                    • J John M Drescher

                                      I believe it should take around or less than 10 seconds on a modern 2GHz processor. My reasoning is that the increment will take 1 clock cycle and the looping should be predicted so that will be like a near jump. I believe that will be less than 4 cycles. So in total less than (or equal to) 5 cycles per loop on a machine that does 2 billion cycles per second...

                                      John

                                      R Offline
                                      R Offline
                                      Rich Leyshon
                                      wrote on last edited by
                                      #32

                                      But what proportion of the total clock cycles available will be allocated to running the application rather than Widows? Is there a general rule of thumb for the percentage of processor time an app can expect (assuming no other major apps are running at the time)? If there is, I'm guessing that it is MUCH lower for Vista than XP - I have an XP app that grinds Vista to a halt! Rich

                                      J 1 Reply Last reply
                                      0
                                      • R Rich Leyshon

                                        But what proportion of the total clock cycles available will be allocated to running the application rather than Widows? Is there a general rule of thumb for the percentage of processor time an app can expect (assuming no other major apps are running at the time)? If there is, I'm guessing that it is MUCH lower for Vista than XP - I have an XP app that grinds Vista to a halt! Rich

                                        J Offline
                                        J Offline
                                        John M Drescher
                                        wrote on last edited by
                                        #33

                                        If no other cpu hogging app is running on (or other cores are free) > 90% otherwise. The time will be several times my 10 second estimate...

                                        John

                                        1 Reply Last reply
                                        0
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • World
                                        • Users
                                        • Groups