Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 14, 2025

🎯 Summary

This pull request implements a comprehensive benchmark suite to compare the performance of CharSegment and Segment<char> as requested in issue #56.

📋 Issue Reference

Fixes #56

🚀 Implementation Details

Added SegmentBenchmarks.cs

A complete benchmark class that compares performance across multiple operations:

  • Hash Code Generation: GetHashCode() performance comparison
  • Equality Comparison: Both self-equality and cross-instance equality tests
  • Index Access: Element access via indexer [i] performance
  • String Conversion: ToString() and implicit string conversion performance
  • Search Operations: Contains() and IndexOf() method performance
  • Collection Conversion: ToArray() and ToList() performance
  • Iteration: foreach loop iteration performance

Benchmark Configuration

  • Uses BenchmarkDotNet with SimpleJob and MemoryDiagnoser
  • Tests multiple data sizes: 10, 100, 1000, 10000 elements
  • Fixed random seed (42) for reproducible results
  • Tests realistic scenarios with offset segments

Updated Program.cs

Modified the benchmark runner to execute the new SegmentBenchmarks instead of BitStringBenchmarks.

🧪 Test Coverage

The benchmark suite provides comprehensive performance analysis to help identify:

  1. Which implementation is faster for specific operations
  2. Memory allocation patterns via MemoryDiagnoser
  3. Performance scaling across different data sizes
  4. Optimization opportunities for both classes

🏃‍♂️ How to Run

cd csharp/Platform.Collections.Benchmarks
dotnet run -c Release

📊 Expected Insights

This benchmark will help determine:

  • Whether CharSegment's specialized char[] optimizations provide measurable benefits
  • Performance differences in hash code calculation and equality checking
  • String conversion performance (implicit conversion vs ToString())
  • Memory allocation differences between the implementations

🤖 Generated with Claude Code

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

Issue: #56
@konard konard self-assigned this Sep 14, 2025
…ment<char>

This benchmark suite compares the performance of CharSegment vs generic Segment<char> across multiple operations:
- Hash code generation
- Equality comparison (self and other instances)
- Index-based element access
- String conversion (ToString and implicit conversion)
- Search operations (Contains, IndexOf)
- Collection conversion (ToArray, ToList)
- Iteration performance (foreach loops)

The benchmarks use fixed random seed for reproducible results and test multiple data sizes (10, 100, 1000, 10000 elements).

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

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Add a benchmark to compare performance of CharSegment and Segment Add comprehensive performance benchmark comparing CharSegment and Segment<char> Sep 14, 2025
@konard konard marked this pull request as ready for review September 14, 2025 04:29
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.

Add a benchmark to compare performance of CharSegment and Segment

2 participants