In SQL Server when I want to check performance, I clear all buffers - in order to get true result : I use
CHECKPOINT 1
DBCC DROPCLEANBUFFERS
dbcc FREEPROCCACHE
and then I check differentials between GetDate()'s
What command should I use in C# in order to clear any buffer/"speed helper" mechanism ? (I'm intending to use stop watch).
THanks.
A .NET program has a lot of 'caches', and not all of them can be cleared. You have the CPU caches that are filled not only by your process, but also by other processes running on your computer. You have the jitter that compiles your functions the first time they're called, making the first iteration a lot longer than any other iteration. If you're using any sort of I/O, you have those caches and buffers as well.
Besides, why would you want to clear the caches? They are there to help you. In the real world, a cache hit will help your performance - why not measure your program's performance while taking caches and buffers into account?
Anyway, I think you should use a profiler instead of a Stopwatch
to measure your performance. That goes for SQL Server as well.