Archived
1
0
Fork
You've already forked TinyProfiler
0
Measure execution time by regions of code
This repository has been archived on 2025年12月05日. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • C# 100%
Find a file
Eric Boumendil 3dc37f1725 reorg files
2014年03月24日 19:21:23 +01:00
TinyProfiler reorg files 2014年03月24日 19:21:23 +01:00
TinyProfiler.UnitTests First commit 2014年03月23日 14:23:55 +01:00
.gitattributes First commit 2014年03月23日 14:23:55 +01:00
.gitignore minor update (.gitignore) 2014年03月24日 18:57:29 +01:00
readme.md minor: readme and nuspec 2014年03月23日 17:53:32 +01:00

TinyProfiler

What is it ?

TinyProfiler is a simple profiling solution, based on the using keyword (it implements IDisposable).
It offers an effective and fast way to measure execution time by regions of code.

You can copy the source into your project or install the nuget package (embeds the source code into your project, no assembly reference required).

Other solutions

If your project is web based, I highly suggest you to go with MiniProfiler.
TinyProfiler is a poor man's profiling solution easy to embed in any .NET 3.5 project without third party assembly reference. I typically put this code in my logging library, and I wire the actual implementation via the application IoC container.

Usage

TinyProfiler is basically a contract based on two interfaces:

  • IProfilerFactory
  • IProfiler : IDisposable

There is an implementation based on a ILogger interface (where to write the measures) but you can easily adapt the code to your needs. There is no wiki but the code is simple and commented. You can also read the unit tests for more samples.

using (var profiler = profilerFactory.StartProfiling("my operation"))
{
	using (var step1 = profiler.StartStep("Step 1"))
	{
		// Lengthy operation...
	}
	
	using (var step2 = profiler.StartStep("Step 2"))
	{
		// Lengthy operation...
	}
}

Output sample:

my operation: 453 ms
 - Step 1: 41 ms
 - Step 2: 412 ms (+41)

Limitations, caveats, known bugs

Let me know if you have troubles with use of this code.