Project Description
The Timekeeper static class is an aid for .Net developers to help in the speed optimization of their code. By placing a simple call at the beginning and all "exit" points to the method, the time the method takes to execute is recorded. It is written in C# using SharpDevelop.

The Timekeeper can handle as many methods you wish as well as tracking the number of times it was called and it's call stack. By default, it will spit out a log file with all the tracked methods list in order by the total time spent in that method with the largest time first. The class contains several helper properties and methods to customize it's results. The timer uses
an unmanaged high precision call to the system timer. The resulting precision is in nanoseconds.

The need for this library came from a complex algorithm that I was developing, and the tools available to me (PartCover being one) did not tell me where the bottlenecks where occurring. As a result, I wrote in some ugly code to track certain method's time. After fiddling with the ugly code to make it more useful, and reusable, I produced Timekeeper, along with a few other helper classes.

I, the author, consider this class to be as complete as I need it to be. If there are other features, or optimizations, or bugs that the users request, I may update it, however, I am not planning on any further updates. It is my wish to see this library implemented as a plugin for SharpDevelop, though that goes beyond what I am willing to produce. Anyone who is interested in participating in this library's maintenance and/or further development, I would appreciate it. I feel this library could be a very useful part of any developer's toolbox, and I would hate to see it fade away.
(Edit: Not even 1 day passed, and I already find myself making corrections and implementing new features......oh well, I guess the development may be more active then I would prefer....)

Example of simplest usage:

At the beginning of the module place the using statement:
using RTenney.Utility.Timekeeping;

At the beginning of the method:
TimeData timer = Timekeeper.StartNew();

At an exit (before return statement):
Timekeeper.End(timer);

And before the program exits, call the Save method:
Timekeeper.Save();

Sample Output file:
This output sample used an optional property:
Timekeeper.StacksToSkip = 2; // Skips the initial Program and MainForm stack frames.

-Total time: 0.000001885715 Called: 1 time, Average time: 0.000001885715 | DungeonGenerator.Generate() => DungeonGenerator.CreateStructure(RPGEngine.StructureTypes type, RPGEngine.Directions dir, System.Drawing.Point connectingPoint) => DungeonGenerator.CreateRoom(RPGEngine.StructureTypes type, RPGEngine.Directions dir, System.Drawing.Point connectingPoint) => DungeonGenerator.IsAreaClear(System.Drawing.Rectangle area) => DungeonGenerator.AreaContainsType(System.Drawing.Rectangle area, RPG_Engine.TileType type) => DungeonGenerator.IsWithinBounds(System.Drawing.Rectangle area)
-Total time: 0.000001885715 Called: 1 time, Average time: 0.000001885715 | DungeonGenerator.Generate() => DungeonGenerator.RandomDirAndConnector(RPG_Engine.Directions& nextDir, System.Drawing.Point& nextConnector, Boolean& connectingFromRoom) => DungeonGenerator.RandomDirection()
-Total time: 0.000002025397 Called: 1 time, Average time: 0.000002025397 | DungeonGenerator.Generate() => DungeonGenerator.CreateStructure(RPGEngine.StructureTypes type, RPGEngine.Directions dir, System.Drawing.Point connectingPoint) => DungeonGenerator.CreateHall(RPGEngine.StructureTypes type, RPGEngine.Directions dir, System.Drawing.Point connectingPoint) => DungeonGenerator.IsAreaClear(System.Drawing.Rectangle area) => DungeonGenerator.AreaContainsType(System.Drawing.Rectangle area, RPG_Engine.TileType type) => DungeonGenerator.IsWithinBounds(System.Drawing.Rectangle area)
-Total time: 0.000002653969 Called: 1 time, Average time: 0.000002653969 | DungeonGenerator.Generate() => DungeonGenerator.CreateStructure(RPGEngine.StructureTypes type, RPGEngine.Directions dir, System.Drawing.Point connectingPoint) => DungeonGenerator.CreateRoom(RPGEngine.StructureTypes type, RPGEngine.Directions dir, System.Drawing.Point connectingPoint) => DungeonGenerator.IsAreaClear(System.Drawing.Rectangle area) => DungeonGenerator.IsWithinBounds(System.Drawing.Rectangle area)
.....output clipped.....

Last edited Mar 26, 2009 at 5:50 PM by rob10e, version 5