I ran this code to see how long it takes my computer to print a number's factorial.
class Integer
 
 def factorial 
  x = self.to_i
  product = 1 * x
 
 while x >= 2 do
   x -= 1
   product *= x
 end 
 
 return product
 end 
 end
 
 require 'benchmark' 
 
 b = Benchmark.measure do
 puts 200000.factorial
 end 
 
 puts b 
 I've only got safari, terminal, text mate, and wonder list open.
I've got the 15" mbp with 4gb of ram running lion.
Here are my ram stats right now.
wired:862MB
 Active 2.56GB
 Inactive 315MB
 Free 286MB
I don't think this is normal.
I printed some massive numbers before I did 200,000. Actually I did 100, 1000, 10,000, 100,000 and then finally 200,000.
Is my ram being used up because of all these numbers I printed?
If so, where can I go to delete them?
EDIT:
Tests
Control
free 270.9
 wired 837.9
 Active 2.12 GB
 Inactive 812.2
 used 3.73
 Terminal Use 35.2MB
 Activity Moniter 30.7MB
Calculating 100,000 factorial AND printing
free 278.6
 wired 829.7
 Active 2.11 GB
 Inactive 817.3
 used 3.72
 Terminal Use 37.9 MB
 Activity Moniter 31.0 MB
Calculating 100,000 factorial WITHOUT printing
free 279.5
 wired 829.0
 Active 2.12 GB
 Inactive 814.5
 used 3.72
 Terminal Use 38.9 MB
 Activity Moniter 31.1 MB
 
No comments:
Post a Comment