how long does it take
-
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
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.
-
how long does it take for a computer to count from 0 to the maximum value of int ??
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 -
Release, Debug or Plain English?
Deja View - the feeling that you've seen this post before.
Pete O'Hanlon wrote:
Plain English
Shhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh!
-
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/2001On 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.
-
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
:laugh: Mine does this all the time - lousy computer!
-
Pete O'Hanlon wrote:
Plain English
Shhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh!
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.
-
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.
Nonsense - Vista recognises such an operation as a security risk, prompts the user for administrative access and then refuses to run the task regardless :)
-
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.
i m doing it just fo fun :d
-
Nonsense - Vista recognises such an operation as a security risk, prompts the user for administrative access and then refuses to run the task regardless :)
doing it under XP Pro SP2
-
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.
Hmmm. I always thought of him as more as a noxious cloud of bum gas: invisible, lingering and stinking up the joint a treat. :)
-
how long does it take for a computer to count from 0 to the maximum value of int ??
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)
-
doing it under XP Pro SP2
I'm not sure I care.
-
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.
-
how long does it take for a computer to count from 0 to the maximum value of int ??
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)
-
how long does it take for a computer to count from 0 to the maximum value of int ??
Longer than im willing to sit there waiting... :D
Mark Brock Click here to view my blog
-
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.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
-
Longer than im willing to sit there waiting... :D
Mark Brock Click here to view my blog
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 -
how long does it take for a computer to count from 0 to the maximum value of int ??
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 negativetaking 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 againThat 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 againThis 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
-
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
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
-
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
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