Here is what I did when I was exploring optimizing the code to run as fast as possible in simulation (here is the blog post describing the things I looked into).
- Add a classical driver to your project that calls your Q# code.
I used C# (you can also use Python if you prefer it) and the code you'll use is going to be something like this:
using QuantumSimulator qsim = new QuantumSimulator();
bool[] result = GroversSearch.Run(qsim).Result.ToArray();
- In this classical driver, wrap the call to quantum operation's
Run
in classical code that tracks the start and the end time. Here is C# code for it:
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
// ... call quantum operation here ...
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
You can do any pre-processing before the call to quantum code and any post-processing afterwards, and they won't count towards the execution time.
You can see the full example here.