Archive

Tuesday, May 8, 2007

Distance and speed of ulong i = 1000000000000

The number is 1 trillion. Not an unheard of number, but still a very long and hard to count number - hell, impossible for the human.

I wrote a code segment in C# to loop through a billion billions, and slowly realized that would take (at least to me) forever. It would take 228,000 years to count to the billionth billion.

for (ulong i = 0; i < 1000000000; i++)
{
for (ulong a = 0; a < 1000000000; a++)
{
}
}



This is based on it taking 2 hours (1hr 54mins) to get to the 1000th billion (1 trillion). This means 2000 hours to get to the millions; and 2,000,000 hours to get to the billionth billion.

Now to get back to where I was, the distance of a 1 trillion iteration loop:
This is based off the speculation that both variables of the loop are stored in the CPU's cache.



Then you must estimate that there is about an inch of travel between where the CPU processes the information and where it grabs the data from the cache and back. So if this is true (I'm pretty sure it is very close to true), you will have 1 trillion inches once you reach 1 the 1000th iteration of the first loop (i).

1,000,000,000,000 inches = 83333333333 feet
83333333333 feet = 15,783,000 miles

So our data traveled around 16 million miles in the 2 hours it was running in that loop! THAT is fast, 8,000,000 mph! Space shuttles in orbit travel at 18,000 mph (~450 times slower).

Now only imagine how far we could go if we could only transport our data :(. The future holds something magical for use humans, and let us hope it is traveling over electrical currents :p.

No comments: