Thursday, August 24, 2006

Throwing RAM at XCode Linking

In my day job, I spend a lot of time compiling and linking a fairly large commercial C++ application. My PowerBook G4 was not up to the task of compiling the whole thing in a reasonable time, although I could distribute the compilation to two G5 desktops when I was at work. But this did not help when I worked from home, nor did it help with linking. And no, zero-link never seems to work for me.

So I bought a MacBook, and home compiles are now peppy. But linking is still fairly slow, especially if I'm running my normal selection of apps, and I rarely compile the whole application, but I have to re-link it every time I want to test a change. I ran the Utility Monitor utility while linking and I was shocked to see that linking, which drags my whole computer down to a crawl, was only using 10% of the CPU; it was crawling because even in 1GB of RAM, linking caused a horrible virtual memory paging thrash. Well, one of the nice things about a MacBook is it is upgradeable to 2GB.

I first measured my linking speed on my 1GB 1.83GHz MacBook with a 5400 rpm SATA 120GB Momentus hard drive. It actually wasn't too bad, linking my work application in an average of 150 seconds. If it was like that all the time, I might not have seen the need to upgrade my memory, but adding applications running concurrently makes linking time progressively worse. Launching Safari, iTunes, and iPhoto and doing light browsing while the link completes, bumps it up to 197 seconds, adding Skype to the mix increases the time to 248 seconds. (150/197/248)

Then I upgraded the RAM to 1.5 GB and the times improved markedly. (91/110/102)

Then I upgraded the RAM to 2.0 GB and the times really got fast. (39/54/61).

XCode Linking Speed versus MacBook RAM

I noticed that as the times got quicker, the fraction of the CPU taken up by the linker (ld) went up. At 1GB of RAM, ld was using at most 14% of the CPU, at 2GB, it was up to 50%. It wasn't spending all it's time paging out. In fact, Activity Monitor
showed only 7 page outs after my testing versus hundreds of thousands of page outs after the 1GB testing.

You might have noticed, I didn't mention the size of my application. That is because, the size of my application is irrelevant to you. The point is, I was having slow linking, and upgrading my memory capacity improved my linking speed by around 4x for an investment of $165 (shipped) in name brand RAM. If you are having a slow linking problem, maybe you will get similar results; but you will have to measure to find out.

My brother Joe also has a RAM hungry program he relies upon, Parallels Desktop, and he tells me that bumping his MacBook to 2GB made it the fastest Windows XP computer he's ever used. (And that's with one core tied behind its back.)

Tuesday, August 15, 2006

Windmill vs. New Refrigerator

Must resist urge to use the word tilting

I recently bought a Kill A Watt energy consumption measuring device, and have become an enthusiast for saving electrical power. Several co-workers have borrowed it and now have a better understanding of how they can conserve power.

In the course of my evangelism, I fell into a conversation with a co-worker who planned to buy and install a windmill on his property in New Hampshire. He feels this is a good way to both save resources and money. I asked him how much electricty he could generate, and he replied that his measurements indicated he could generate an average of 450 Watts. At $0.15 per kWh, this would be around $45 a month in energy. I asked him how much a windmill costs: $4000. How long would it last: 30 years with little maintenance.

By way of comparison, I had lent my Kill-A-Watt to another fellow, who reported back that his 15+ year old refrigerator was using $45 a month in energy. My refrigerator uses $12 a month in electricity, so this person could save $33 a month if he were only to buy as efficient a refrigerator as mine. Checking online, indicates a refrigerator should last for 15 years, and a top rated model (by Consumer Reports) such as the Whirlpool ET1FHTXMQ costs $750.

So the question is: If I had $4000 should I get a new refrigerator, or a windmill? (this thought experiment does not take into account subsidies, inflation or taxes). Interest income calculated using this online calculator.

Scenario 1 (buy windmill)
Initial investment account balance: $0
Return on energy generated: $45/month
Investment account balance after 30 years (assuming 8% return):$67513

Scenario 2: (buy $750 refrigerator and replace it again in 15 years)
Initial investment account balance: $3250
Return on energy saved: $33/month
Investment account balance after 30 years (assuming 8% return):$82571

Scenario 3: (buy neither)
Initial investment account balance: $4000
Investment account balance after 30 years (assuming 8% return):$43743

So, from a purely monetary point of view, investing in a new refrigerator is better than buying a windmill if your old refrigerator needs replacing. And if you have both an old refrigerator and an old dehumidifier, I suspect you will end up saving as much energy as a windmill generates at a fraction of the price. The guy with the bad refrigerator was also spending $60 per month on dehumidification.

The amazing thing for me is that the 50+% return you can get from buying a new refrigerator makes it such an incredibly good deal if your old refrigerator is inefficient. (Over 15 years you save $6000 in energy costs, which if invested at 8% would yield $11,500) Obviously, not everyone has such an old clunker as my co-worker. Your mileage may vary, but I highly recommend getting a Kill-A-Watt and finding out.