DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Ruby (http://www.daniweb.com/forums/forum73.html)
-   -   Ruby: Count to 1 Billion, basing from a C++ Code (http://www.daniweb.com/forums/thread193203.html)

ClimaxBeetle May 21st, 2009 12:14 pm
Ruby: Count to 1 Billion, basing from a C++ Code
 
How long does it take to count 1 billion?
Determine the amount of time it takes the program.

Int i,j,k, count=0;
For (i=0; i<N; i++)
        For (j=0; j<N; j++)
                For (k=0; k<N; k++)
                        count++

to complete in your programming environment, for N=1000, and 1000. If your compiler has optimization features that are supposed to make a program more efficient, check whether or not they do for this program.

However, this code below was the cheapest and the cheating way to fulfill how long will it count to 1Billion.
for k in 1..1000000000
  print k," "
end
print "\n"

Note, this is my first time to get up close and personal with Ruby, not just the Ruby in RPG Maker XP.


All times are GMT -4. The time now is 12:23 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC