Storing the first 5000000 Fibonacci numbers using YARV's implementation of Integer
uses exactly 1084762047712 bytes (assuming 8 bits per byte) on a 64 bit platform. That's close to one TiByte (0.9865853351 TiByte, to be precise). And that's just the space for the numbers themselves, there's also the overhead for the array (a couple of bytes) and the pointers inside the array (a little bit less than 5000000 times 8, or a little over 38 MiByte).
Computing those 5000000 numbers even without storing them (only remembering the last 2 to avoid re-computation), took a little over 20 minutes on my late 2011 model MacBook Pro. Computing them while at the same time allocating 1 TiByte of RAM is going to be much slower. If you don't have 1 TiByte of RAM, and the OS starts swapping out to disk, it is going to be orders of magnitude slower, even if you have a blazing RAID of SSDs connected via FibreChannel.
In order to print the array, it needs to be represented as a string first. Even just the commas and spaces without the numbers are already 4999999*2 characters, which need close to 10 MiByte of RAM (assuming a single-byte character set). If you tried to print out just the commas and spaces, you would need about 2500 pages of DIN A4 paper, or 1250 sheets if you print double-sided. Office paper is typically sold in stacks of 500 sheets which are roughly 5 cm high, so you have 2.5 stacks about 12.5 cm high just for the commas and spaces.
The total number of digits, and thus characters (and bytes) for the 5000000 numbers, is roughly 2.7 trillion digits, that's about 2.5 TiByte of RAM for the final string to be printed. Printing that out on DIN A4 double-sided would result in a stack of paper 33 km high, 4 times the height of Mt. Everest.
All in all, at the point that you are calling print
, your program needs about 3.5 TiByte of RAM.
Printing to the console is actually surprisingly slow, on my standard macOS Terminal.app, I get about 1 MiByte/s, which means that not only will calculating the 5000000 numbers take at least tens of minutes without even counting the time for allocating all those objects and all that RAM, not only will your program use 3.5 TiByte of RAM, just the act of displaying the final array on the terminal will take about one month.
tl;dr summary: 5000000 Fibonacci numbers are big.