SmartCodeComplexityDetector 1.0.0

dotnet add package SmartCodeComplexityDetector --version 1.0.0
                    
NuGet\Install-Package SmartCodeComplexityDetector -Version 1.0.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="SmartCodeComplexityDetector" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SmartCodeComplexityDetector" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SmartCodeComplexityDetector" />
                    
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 SmartCodeComplexityDetector --version 1.0.0
                    
#r "nuget: SmartCodeComplexityDetector, 1.0.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.
#:package SmartCodeComplexityDetector@1.0.0
                    
#: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=SmartCodeComplexityDetector&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SmartCodeComplexityDetector&version=1.0.0
                    
Install as a Cake Tool

Smart Code Complexity Detector for .NET

โšก Built with Roslyn for seamless integration in Visual Studio
๐Ÿ’ก No config required โ€” works out of the box
๐Ÿง  Helps you code smarter, faster, and cleaner

๐Ÿš€ Features

โœ… Time Complexity Estimation (O(1), O(n), O(nยฒ), etc.)
โœ… Space Complexity Estimation
โš ๏ธ Anti-pattern Detection (e.g., nested loops, inefficient LINQ)
๐Ÿ’ฌ Inline Suggestions powered by Roslyn
๐Ÿงช Test Coverage Warnings (optional)
๐Ÿ–ฅ๏ธ Optional: Visual Studio Extension for enhanced popup UI (Coming Soon)

๐Ÿ“ฆ Installation

dotnet add package SmartCodeComplexityDetector

๐ŸŽฏ Quick Start

Just write your code as usual. The analyzer will analyze your methods as you type and show diagnostics:

public void PrintDuplicates(int[] nums)
{
    for (int i = 0; i < nums.Length; i++)
        for (int j = i + 1; j < nums.Length; j++)
            if (nums[i] == nums[j])
                Console.WriteLine(nums[i]);
}

Tooltip will show:

Time Complexity: O(nยฒ)
Space Complexity: O(1)
Suggestion: Consider using HashSet for better performance

๐Ÿ“– Usage Examples

Basic Analysis

using SmartCodeComplexityDetector.Core;

string sourceCode = @"
public class Example
{
    public void PrintDuplicates(int[] nums)
    {
        for (int i = 0; i < nums.Length; i++)
            for (int j = i + 1; j < nums.Length; j++)
                if (nums[i] == nums[j])
                    Console.WriteLine(nums[i]);
    }
}";

// Analyze a specific method
var result = SmartCodeComplexityDetector.AnalyzeMethod(sourceCode, "PrintDuplicates");
Console.WriteLine(SmartCodeComplexityDetector.FormatResult(result));

Quick Analysis

// Get just the complexity notations
var (timeComplexity, spaceComplexity) = SmartCodeComplexityDetector.QuickAnalysis(sourceCode, "PrintDuplicates");
Console.WriteLine($"Time: {timeComplexity}, Space: {spaceComplexity}");

Analyze All Methods

// Analyze all methods in a file
var allResults = SmartCodeComplexityDetector.AnalyzeAllMethods(sourceCode);
foreach (var (methodName, result) in allResults)
{
    Console.WriteLine($"Method: {methodName}");
    Console.WriteLine(SmartCodeComplexityDetector.FormatResult(result));
    Console.WriteLine();
}

๐Ÿ” What It Detects

Time Complexity Analysis

  • O(1): Constant time operations
  • O(n): Linear operations (single loops, LINQ)
  • O(nยฒ): Quadratic operations (nested loops)
  • O(nยณ): Cubic operations (deeply nested loops)
  • O(log n): Logarithmic operations
  • O(n log n): Linearithmic operations

Space Complexity Analysis

  • O(1): Constant space usage
  • O(n): Linear space usage (arrays, lists)
  • O(nยฒ): Quadratic space usage

Anti-pattern Detection

  • โš ๏ธ Nested loops that could be optimized with HashSet/Dictionary
  • โš ๏ธ Inefficient LINQ operations (multiple Where clauses, unnecessary ToList())
  • โš ๏ธ String concatenation in loops (should use StringBuilder)
  • โš ๏ธ Unnecessary allocations (List without capacity, arrays without size)

Optimization Suggestions

  • ๐Ÿ’ก Use HashSet for O(1) lookups instead of nested loops
  • ๐Ÿ’ก Combine multiple Where clauses into a single Where
  • ๐Ÿ’ก Use StringBuilder for string concatenation in loops
  • ๐Ÿ’ก Specify initial capacity for List<T> creation
  • ๐Ÿ’ก Use Any() instead of Count() > 0

๐Ÿ› ๏ธ Advanced Usage

Custom Analysis

// You can also use the underlying services directly
using SmartCodeComplexityDetector.Services;
using SmartCodeComplexityDetector.Interfaces;

var antiPatternDetector = new AntiPatternDetector();
var complexityAnalyzer = new ComplexityAnalyzer(antiPatternDetector);

// Analyze with more control
var result = complexityAnalyzer.AnalyzeMethod(sourceCode, "MethodName");

Integration with Build Tools


<ItemGroup>
  <PackageReference Include="SmartCodeComplexityDetector" Version="1.0.0" />
</ItemGroup>

๐ŸŽจ Output Examples

Simple Method

public int Sum(int[] numbers)
{
    int sum = 0;
    foreach (int num in numbers)
        sum += num;
    return sum;
}

Output:

Time Complexity: O(n)
Space Complexity: O(1)
Explanation: The method contains linear iterations (loops, LINQ operations) that process each element once. The method uses only a constant amount of additional memory.

Complex Method with Anti-patterns

public List<int> FindDuplicates(int[] nums)
{
    var result = new List<int>();
    for (int i = 0; i < nums.Length; i++)
    {
        for (int j = i + 1; j < nums.Length; j++)
        {
            if (nums[i] == nums[j])
                result.Add(nums[i]);
        }
    }
    return result;
}

Output:

Time Complexity: O(nยฒ)
Space Complexity: O(n)
Explanation: The method contains nested loops, resulting in quadratic time complexity. The method allocates memory proportional to the input size (arrays, lists, etc.).

Suggestions:
โ€ข Consider using HashSet or Dictionary for O(1) lookups instead of nested loops
โ€ข Look for opportunities to use sorting + binary search for O(n log n) instead of O(nยฒ)

Anti-patterns detected:
โš ๏ธ Nested loops detected - consider using HashSet or Dictionary for O(1) lookups

๐Ÿ”ง Configuration

The package works out of the box with sensible defaults. No configuration required!

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

  • ๐Ÿ“ง Email: support@smartcomplexitydetector.com
  • ๐Ÿ› Issues: GitHub Issues
  • ๐Ÿ“– Documentation: Wiki

๐Ÿš€ Roadmap

  • Visual Studio Extension with real-time analysis
  • Integration with CI/CD pipelines
  • Custom complexity rules
  • Performance benchmarking suggestions
  • Memory usage analysis
  • Async/await complexity analysis

Made with โค๏ธ for the .NET community

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in 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
1.0.0 129 8/4/2025