EnergyAnalyzer 0.1.3

dotnet add package EnergyAnalyzer --version 0.1.3
                    
NuGet\Install-Package EnergyAnalyzer -Version 0.1.3
                    
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="EnergyAnalyzer" Version="0.1.3">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EnergyAnalyzer" Version="0.1.3" />
                    
Directory.Packages.props
<PackageReference Include="EnergyAnalyzer">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 EnergyAnalyzer --version 0.1.3
                    
#r "nuget: EnergyAnalyzer, 0.1.3"
                    
#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.
#:package EnergyAnalyzer@0.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EnergyAnalyzer&version=0.1.3
                    
Install as a Cake Addin
#tool nuget:?package=EnergyAnalyzer&version=0.1.3
                    
Install as a Cake Tool

Energy Analyzer

NuGet Status Build Status Coverage Status License LOC

EnergyAnalyzer is a collection of Roslyn Analyzers that can be used to improve the energy efficiency of C# programs.

This project was developed during a masters thesis at Aalborg University, Denmark. The project can be found here (Not published yet).

The suggestions and code fixes implemented in EnergyAnalyzer are based on Benchmarking C# for Energy Consumption (PDF)

The results gathered in both projects are found using CsharpRAPL which is a framework created to benchmark different language constructs in C#.

Further benchmarks can be found here or in the '3rd Party Example Projects' folder.

You can get the analyzer from NuGet here.

Features

The analyzer supports giving suggestions regarding the following topics, with code fixes for some of them (specified):

  • Collections:
    • Array (Has code fix)
    • List (Has code fix)
    • Dictionary (Has code fix)
    • Set (Has code fix)
  • Datatypes:
    • Floating Point Numbers (Has code fix)
    • Integer Numbers (Has code fix)
    • String Concatenation
    • Unboxing (Has code fix)
  • Exceptions:
    • Efficient Exceptions (Has code fix)
    • Replacing Exceptions
  • Invocations:
    • Lambda Expressions (Has code fix)
    • Reflection (Has code fix)
  • LINQ:
    • Replacing LINQ
  • Loops:
    • Efficient Loops (Has code fix)
  • Object:
    • Class vs. Struct (Has code fix)
  • Selection:
    • If vs. Switch (Has code fix)

Installation

To install the package, run the following command:

Install from NuGet

Nuget Manager

Select the NuGet Package Manager from the Tools menu.

Search for EnergyAnalyzer and click the Install button.

Nuget Console

You can install the package from NuGet by one of the following ways:

Install-Package EnergyAnalyzer
dotnet CLI
dotnet add package EnergyAnalyzer
csproj reference
<PackageReference Include="EnergyAnalyzer" Version="0.1.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

Examples

Examples of the changes the tool can make can be seen in the folder "3rd Party Example Projects", where we have used the analyzer to create various versions of the programs. Such that projects named CodeFixes are the ones that have been changed by the automatic changes and All is where both code fixes and suggestions have been implemented.

Provided is also tasks and examples used for a usability test which resides here.

License

MIT License

Errors

When building your solution you might encounter warnings similar to the one below:

 An instance of analyzer EnergyAnalyzer cannot be created from ... : Could not load file or assembly ... or one of its dependencies. The system cannot find the file specified..

This warning does not mean that the analyzer is not working correctly.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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
0.1.3 571 5/19/2022
0.1.2 528 5/18/2022
0.1.1 540 5/18/2022
0.1.0 531 5/17/2022
0.0.19 498 5/17/2022
0.0.18 497 5/12/2022
0.0.17 526 5/11/2022
0.0.16 474 5/11/2022
0.0.15 489 5/11/2022
0.0.14 479 5/10/2022
0.0.13 499 5/10/2022
0.0.12 505 5/10/2022
0.0.11 490 5/9/2022
0.0.10 501 5/9/2022
0.0.9 505 5/9/2022
0.0.8 287 5/6/2022
0.0.7 192 5/6/2022
0.0.6 515 5/5/2022
0.0.4 504 5/2/2022
0.0.3 484 5/2/2022
0.0.2 510 4/29/2022
0.0.1 493 4/29/2022