I do not think you can do this.
The best effort, for me, would be to put your method in a separate thread and use
Thread.CurrentThread.Priority = ThreadPriority.Highest;
to avoid as much context switching as possible.
If I may ask, why do you need such an accurate measurement, and why you cannot extract this function and not compare it in your own program, if that is the point?
Edit: depending on the use case, it may be useful to use
Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(2);
to avoid switching between cores.
source share