PerfEvent 0.3.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package PerfEvent --version 0.3.0
                    
NuGet\Install-Package PerfEvent -Version 0.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PerfEvent" Version="0.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PerfEvent" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="PerfEvent" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PerfEvent --version 0.3.0
                    
#r "nuget: PerfEvent, 0.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=PerfEvent&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=PerfEvent&version=0.3.0
                    
Install as a Cake Tool

PerfEvent

This is a small helper library to measure instruction counts as reported by hardware events for benchmarks. It uses the Linux perf_event_open syscall, which is not available on any other platform. I.e. this only works under Linux.

However, since it doesn't throw exceptions when it's not used, you should be able to include this project as a dependency under any platform, as long as you only use it under Linux.

How do you use it?

Currently, it works as follows:

using var instructionCounter = new InstructionCounter();
// ... do something here ...
instructionCounter.Dispose();

Console.WriteLine($"Used {instructionCounter.RecordedInstructions} instructions.");

The usual benchmarking rules still apply: You should generally try to call the method you're trying to benchmark before you measure a couple of times to make sure that you're not measuring the JIT, and you should measure the overhead of measuring itself, too, to get accurate results.

Why shouldn't I just use the perf command?

The point of measuring 'instructions retired' instead of 'time elapsed' is that the former is much more stable than the latter. If you're wondering "did my code just get faster by this change?", but you expect only a few percent increase, it might make more sense to use instruction count as a metric instead of time, since that will get you a more reliable result, meaning that you only have to measure once or twice (as opposed to hundreds of times).

With perf, you have two options to get those results:

  1. Attach to a running process. This can be done just before the call that you want to measure, but you'll have to wait a little until you can be sure that perf attached properly. Also, you need root permissions to do so.
  2. Run the entire process with perf stat, e.g. perf stat dotnet run. This, however, will measure all kinds of things that you didn't actually want to incorporate and that might produce noise, in particular JIT overhead. Also, it makes it much harder to measure individual function calls.

So, yeah, it's more attractive to use the system call directly.

Building and running

Running the tests:

dotnet test

To create the NuGet package, run:

dotnet build --configuration Release
nuget pack

(Obviously, you need to have NuGet installed to do so.)

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated