You want some processor affinity (or CPU affinity).
The relevant syscall is sched_setaffinity(2), but you should use it thru pthread_set_affinity_np(3) if you want to code your benchmarks for that.
The related command is taskset(1) and you might use it on the commands you want to benchmark (or on your shell).
If possible, take care that the machine is not loaded a lot by other tasks unrelated to the benchmark.
Alternatively, use some hypervisor like Xen, and boot your Linux as a guest OS for that hypervisor. Then configure
xen to use only some restricted set of CPU cores (I don't know the exact details, you need to find out). On Debian (and related) distributions, you might install packages like
xen-utils etc (I'm using on Debian/Sid
There might be perhaps some way of configuring (perhaps at kernel-compilation time, or by passing specific arguments to the kernel thru Grub loader) your Linux kernel to restrict the number of usable cores.
Of course, it is better, when benchmarking some program -e.g. on a desktop Linux PC-, to take care to avoid having many outside running processes (use
top to find these). At least, close and quit most interactive applications (browser like firefox, email, editor, IDEs like Eclipse) and keep only a small number of terminals to benchmark. You might even benchmark in batch mode (using
at to run the benchmarks) while you are not even logged in (so don't have any GUI sessions à la Gnome or KDE or Xfce, etc... running).