Is there an optimal setting for the number of CPU cores exposed to a VM?
The information in this answer is no longer correct. It was correct back in the days of strict co-scheduling, but is no longer the case.
I am keeping the answer below for posterity's sake, but please do not rely on it to be accurate for modern hypervisors.
You should never assign all your cores as vCPUs in a virtual machine.
If a VM requests any CPU time, VMWare must allocate either all the vCPUs or none of the vCPUs.
What this means is, on a 4-core system if you allocate all 4 cores, then only either the host, or the guest, can be allocated processor time, not both at the same time.
This will absolutely ruin performance in both environments.
Feel free to allocate an odd number of cores (say, 3). It may feel strange, but it's a totally legitimate option.
Generally, I never allocate more than n/2 vCPUs (in your case, 2), but I'm normally allocating cores on servers with between 12 and 32 cores where you can allocate many vCPUs without major impact.
It entirely depends on what the guest OS is doing. In my personal experience a VM is running a single program (build server, trac server, SVN, etc) so there is no reason to set it above one.
A possible case may be if it's an end user on say a University that is using the guest OS as a throwaway (i.e. TAs) then maybe set it to higher than one.
The number of cores exposed to guest CPUs does not affect performance as much as you would like. It merely adjusts the amount of cores the guest CPU "sees".
Depending on how the emulator is set up, it could literally half the performance of the virtual machine, do nothing, or only impact the way the guest OS/applications split up their thread scheduling.
It's best to leave it to the default. If you encounter performance issues on the host PC, then you can simply adjust the process priority with the Windows Task Manager.