Which OS is faster for my iMac Early 2009?
Solution 1:
I'm was sorely rempted to -1 your question and then comment, but the comment grew long. You're just trying to make the most of what you have and asking for advice so that's a +1 now.
Unless you define what "fast" is - it's hard for this not to be entirely speculative. Worse, when you define fast - then you make it very narrow and less useful.
The OS doesn't really change your CPU and your memory speeds. It doesn't change your filesystem and since you can't run High Sierra and APFS - you're stuck on HFS+ for that Mac.
About the best thing that can come of this "let's get an answer on which is faster - 10.11 or 10.12 or 10.10" is the suggestion to partition your drive and test each OS to your needs and then make your call.
The downside is you'll likely lose so much more time doing the measuring than just installing the latest OS that runs and then look to optimize what your bottleneck is when you reach them. Another downside would be if someone saw "10.12 is slow" and it discourage them from upgrading when for them it would be faster and/or more secure and no more slow.
I'd say - make a good backup, and then upgrade to the latest OS you can. Old software and not keeping your drive clean from needless files is likely to be far slower than whatever marginal difference you could ever measure on OS versions.
The upside of this is you'll have learned some skills on measuring performance and thinking about the end goal "swift and Xcode" and then can make decisions like - should I spend $$ on RAM and SSD or find a used Mac with those that is more economical than upgrading a core2 duo machine.
Solution 2:
With only 2GB for RAM, you can only run OS X Lion, as other System updates require 2GB of RAM, but run optimally with ~8GB. You are welcome to upgrade this to run a newer OS, but you will need to buy more RAM. Apple’s website says that your Mac can support
2GB (two 1GB SO-DIMMs) or 4GB (two 2GB SO-DIMMs) of 1066MHz DDR3 SDRAM; two SO-DIMM slots support up to 8GB
For more info, you can see this article on the Apple Support Site.
As with any Mac, the factory OS will always be the fastest, but for the best security, the newest is best. Since you are on the lowest specs, Snow Leapord is likely the best way to go.
Another way to make your iMac blazing fast is to install an SSD instead of the factory HDD. Step step to do this can be found on iFixit