Performance tuning/ Query tuning in SQL Server is a combo of art and science. During the query tuning, we sometimes need to clear the cache for actual benchmarking purposes. Here is the code to do that:
To clear data from cache globally:
To clear execution plans from cache globally:
To clear execution plans of a particular database:
The above command is undocumented.
Note: Be careful of using the above commands in your productuon enviornments. It may impact performence negatively to a good extent. We use it more to analyze performance in test enviornments.