SmartCodeComplexityDetector 1.0.0
dotnet add package SmartCodeComplexityDetector --version 1.0.0
NuGet\Install-Package SmartCodeComplexityDetector -Version 1.0.0
<PackageReference Include="SmartCodeComplexityDetector" Version="1.0.0" />
<PackageVersion Include="SmartCodeComplexityDetector" Version="1.0.0" />
<PackageReference Include="SmartCodeComplexityDetector" />
paket add SmartCodeComplexityDetector --version 1.0.0
#r "nuget: SmartCodeComplexityDetector, 1.0.0"
#:package SmartCodeComplexityDetector@1.0.0
#addin nuget:?package=SmartCodeComplexityDetector&version=1.0.0
#tool nuget:?package=SmartCodeComplexityDetector&version=1.0.0
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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- 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 | Versions 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. |
-
net8.0
- Microsoft.CodeAnalysis.Analyzers (>= 3.3.4)
- Microsoft.CodeAnalysis.Common (>= 4.8.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
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 |