Timer Code for Benchmarking

Two topics today:

Benchmarking Add-ins

Just like most programming issues, many Revit API tasks can be achieved in numerous different ways. The optimal approach often depends on your individual needs. The only way to find out which one that may be is to test it. In order to test it effectively, you need to measure the results. One of the most important aspects is often the time required, the execution performance. Measuring a short duration of time precisely makes use of a timer. The .NET framework provides several timer classes for this purpose. Here is a related question that just came up on this topic:

Question: How can I add a timer to my Revit 2012 C# code to find out how much time it takes to execute the whole command? Is there a way to add a form to show total time taken to run the command? I am not quite sure how to wrap the timer class around Revit code.

Answer: The Building Coder samples include several examples of benchmarking both entire commands and individual function calls or sections of code.

They define the JtTimer class, which is one possible wrapper for the .NET Stopwatch class that you may find useful. Besides the Stopwatch wrapper, it also implements a TimeRegistry for keeping track of and summing up the results a number of different Stopwatch instances:

Hands-on Revit API Trainings

If you are interested in face-to-face hands-on training in the Revit API, you should take a regular look at the ADN Training Course Schedule and enter "Revit API" as the course name. Here is the short course description.

The next scheduled class that I will be conducting is taking place in Munich, Germany, starting April 25th (register).

If you are interested in participating in a class, you will benefit enormously by preparing appropriately. The material we provide for that can also be used just as well to efficiently learn the basics of the Revit API for yourself all on your own.