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 ??

    M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #11

    If a program encounters a loop in a forest, does the computer actually execute it? Marc

    Thyme In The Country Interacx My Blog

    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 ??

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

      Release, Debug or Plain English?

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

      My blog | My articles

      M 1 Reply Last reply
      0
      • Y yassir hannoun

        Gary Kirkham wrote:

        it could be skipping the loop altogether and laughing at you behind your back.

        hehehehe anyway it is runing for more than 1 hour so far what i got is 154500000

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

        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 L 2 Replies Last reply
        0
        • O Oakman

          Gary Kirkham wrote:

          laughing at you behind your back.

          Mine does that a lot!

          Jon Smith & Wesson: The original point and click interface

          G Offline
          G Offline
          Gary Kirkham
          wrote on last edited by
          #14

          I would settle for that...mine openly mocks me.

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

          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 ??

            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
            • 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
              #16

              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
              • 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
                #17

                Pete O'Hanlon wrote:

                Plain English

                Shhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh!

                P 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
                                          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