Should I write an email to the professor I want to work with regarding my performance in the exam?
From your explanation I assume that you are very keen to work with him/her in future as a PhD student. So you were trying to your best to do very good in his/her paper. How about your project work? I assume that it was appreciated by your professor, but doesn't matter.

To answer your question, you can always write emails to him/her mentioning about the project work and future advice. So if you write emails, then forget about the exam results and no need to mention about the performance of this exam in your email.

I would prefer to take an appointment after the exam and meet him to discuss about my interest to work with him as a PhD student.