It is tough to say which is worse since the credit reporting agencies won't disclose how your credit score is tabulated. Both bankruptcy and foreclosure are public records and can appear on your credit report for up to 10 years, and both may hit your credit score for around 75 to 150 points depending on factors the credit reporting agencies won't disclose.
If you are debating whether to file bankruptcy on a home or let it be foreclosed, I will tell you that bankruptcy often includes a foreclosure, and foreclosure sometimes compels a bankruptcy, so you may be looking at both.
In other words, when some files bankruptcy to surrender a home and discharge the debt, the lender still normally has to foreclose the home to get the person's name off the deed and the new buyer on it. Sometimes the lender will accept a deed in lieu of foreclosure instead of foreclosing, but they will sometimes do this even without bankruptcy.
Also, if a foreclosure sale takes place and the house does not sell for enough to pay the balance, in many states the lender is permitted to still go after the former homeowner for the balance that was unpaid (called the "deficiency balance"), which often forces the former homeowner to file bankruptcy to discharge the deficiency balance.
I hope this helps and a positive feedback is always appreciated if this was useful to you.
LEGAL NOTICE: I am only licensed to practice law in certain state(s) and I cannot give legal advice to someone who does not reside in a state in which I am licensed, nor shall anything I say in the above answer or elsewhere on this site be deemed legal advice, even to someone who resides in a state in which I am licensed. Fees I receive for answering questions are paid for information, not for legal advice. This forum is designed to provide general information only, and information herein is not warranted to be correct or applicable in any way since laws may have been misinterpreted herein, since laws change from time to time, and since the impact of those laws on any particular situation varies. The information presented in this site shall not be construed to be formal legal advice nor the formation of an attorney-client relationship. Persons accessing this response are encouraged to seek independent legal counsel in their jurisdiction for guidance regarding their individual circumstances. Do not take any action or inaction based on information presented herein since it is informational and may not be accurate or applicable to you; it merely attempts to give you a basis of knowledge to help you formulate questions to ask a legal or other professional in a face-to-face meeting in your jurisdiction. Joseph Ross does not hold himself out to be a specialist or expert in any area, regardless of assertions made by any third party, and any implication of being an expert or specialist herein is made in error. I hope the information presented above is useful to you. Answer above is (c) Joseph Ross. All rights reserved.