Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 14, 2025

Summary

This PR implements performance comparison tests and benchmarks to measure the performance difference between dynamic operations and other generic approaches, as requested in issue #68.

Implementation Details

Added Files

  • ComparisonTests.cs: Unit tests comparing different generic addition approaches
  • EqualityTests.cs: Unit tests comparing different generic equality approaches
  • DynamicVsGenericBenchmarks.cs: Performance benchmarks using BenchmarkDotNet

Performance Approaches Compared

Based on the StackOverflow solution referenced in the issue (https://stackoverflow.com/a/8122675/710069):

  1. INumber approach (NET 7+ - best performance)

    • Uses the new .NET 7+ generic math interfaces
    • Provides compile-time type safety and best runtime performance
  2. EqualityComparer approach (good performance)

    • Uses EqualityComparer<T>.Default for equality comparisons
    • Well-optimized standard approach
  3. Expression-based approach (moderate performance)

    • Compiles expressions at runtime and caches them
    • Good balance between flexibility and performance
  4. Dynamic approach (slowest performance)

    • Uses C#'s dynamic keyword for operations
    • Most flexible but with significant performance overhead

Test Results

All tests pass successfully:

  • ✅ ComparisonTests: Tests addition operations across all approaches
  • ✅ EqualityTests: Tests equality operations across all approaches
  • ✅ All existing tests continue to pass

Benchmark Usage

To run the performance benchmarks:

cd csharp/Platform.Data.Doublets.Benchmarks
dotnet run -c Release

The benchmarks will show the actual performance differences between:

  • INumber addition vs Dynamic addition vs Expression addition
  • IEqualityOperators equality vs Dynamic equality vs Expression equality vs EqualityComparer

Test plan

  • Unit tests created and passing
  • Benchmarks compile successfully
  • All existing tests continue to pass
  • Code follows project conventions

🤖 Generated with Claude Code


Resolves #68

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #68
@konard konard self-assigned this Sep 14, 2025
…c operations

Implements performance comparison between different approaches for generic operations based on https://stackoverflow.com/a/8122675/710069:

- INumber<T> approach (NET 7+ - best performance)
- Expression-based approach (moderate performance)
- Dynamic approach (slowest performance)
- EqualityComparer approach (good performance)

Added files:
- ComparisonTests.cs: Unit tests comparing different generic addition approaches
- EqualityTests.cs: Unit tests comparing different generic equality approaches
- DynamicVsGenericBenchmarks.cs: Performance benchmarks using BenchmarkDotNet

Updated Program.cs to include the new benchmark suite.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] How slow is the dynamic? Add performance comparison tests for dynamic vs generic operations Sep 14, 2025
@konard konard marked this pull request as ready for review September 14, 2025 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How slow is the dynamic?

2 participants