From af04dbdd4a43a19f63853228c231a09fbff137c0 Mon Sep 17 00:00:00 2001 From: konard Date: Sun, 14 Sep 2025 07:24:26 +0300 Subject: [PATCH 1/3] Initial commit with task details for issue #56 Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: https://github.com/linksplatform/Collections/issues/56 --- CLAUDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..9cc864b5 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +Issue to solve: https://github.com/linksplatform/Collections/issues/56 +Your prepared branch: issue-56-e9dd2c77 +Your prepared working directory: /tmp/gh-issue-solver-1757823859092 + +Proceed. \ No newline at end of file From 0f360f4121a154e57a1f3449bb6c19435e8cb98c Mon Sep 17 00:00:00 2001 From: konard Date: Sun, 14 Sep 2025 07:28:46 +0300 Subject: [PATCH 2/3] Add comprehensive performance benchmark comparing CharSegment and Segment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This benchmark suite compares the performance of CharSegment vs generic Segment 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 --- .../Program.cs | 2 +- .../SegmentBenchmarks.cs | 155 ++++++++++++++++++ 2 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 csharp/Platform.Collections.Benchmarks/SegmentBenchmarks.cs diff --git a/csharp/Platform.Collections.Benchmarks/Program.cs b/csharp/Platform.Collections.Benchmarks/Program.cs index cbde7630..30387451 100644 --- a/csharp/Platform.Collections.Benchmarks/Program.cs +++ b/csharp/Platform.Collections.Benchmarks/Program.cs @@ -4,6 +4,6 @@ namespace Platform.Collections.Benchmarks { static class Program { - static void Main() => BenchmarkRunner.Run(); + static void Main() => BenchmarkRunner.Run(); } } diff --git a/csharp/Platform.Collections.Benchmarks/SegmentBenchmarks.cs b/csharp/Platform.Collections.Benchmarks/SegmentBenchmarks.cs new file mode 100644 index 00000000..0c33c026 --- /dev/null +++ b/csharp/Platform.Collections.Benchmarks/SegmentBenchmarks.cs @@ -0,0 +1,155 @@ +using BenchmarkDotNet.Attributes; +using Platform.Collections.Segments; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Platform.Collections.Benchmarks +{ + [SimpleJob] + [MemoryDiagnoser] + public class SegmentBenchmarks + { + [Params(10, 100, 1000, 10000)] + public int Length { get; set; } + + private char[] _data = null!; + private CharSegment _charSegment = null!; + private Segment _segment = null!; + private string _testString = null!; + + [GlobalSetup] + public void Setup() + { + var random = new System.Random(42); // Fixed seed for reproducible results + _data = new char[Length * 2]; // Make it larger to test different offsets + + // Fill with random characters + for (int i = 0; i < _data.Length; i++) + { + _data[i] = (char)('a' + random.Next(26)); + } + + int offset = Length / 4; // Use some offset to test realistic scenarios + + _charSegment = new CharSegment(_data, offset, Length); + _segment = new Segment(_data, offset, Length); + _testString = new string(_data, offset, Length); + } + + [Benchmark] + public int CharSegmentGetHashCode() => _charSegment.GetHashCode(); + + [Benchmark] + public int SegmentGetHashCode() => _segment.GetHashCode(); + + [Benchmark] + public bool CharSegmentEqualsItself() => _charSegment.Equals(_charSegment); + + [Benchmark] + public bool SegmentEqualsItself() => _segment.Equals(_segment); + + [Benchmark] + public bool CharSegmentEqualsOther() + { + var other = new CharSegment(_data, _charSegment.Offset, _charSegment.Length); + return _charSegment.Equals(other); + } + + [Benchmark] + public bool SegmentEqualsOther() + { + var other = new Segment(_data, _segment.Offset, _segment.Length); + return _segment.Equals(other); + } + + [Benchmark] + public char CharSegmentIndexAccess() + { + char result = '\0'; + for (int i = 0; i < _charSegment.Count; i++) + { + result ^= _charSegment[i]; + } + return result; + } + + [Benchmark] + public char SegmentIndexAccess() + { + char result = '\0'; + for (int i = 0; i < _segment.Count; i++) + { + result ^= _segment[i]; + } + return result; + } + + [Benchmark] + public string CharSegmentToString() => _charSegment.ToString(); + + [Benchmark] + public string SegmentToString() => _segment.ToString() ?? string.Empty; + + [Benchmark] + public string CharSegmentImplicitConversion() => _charSegment; + + [Benchmark] + public bool CharSegmentContains() + { + char searchChar = _data[_charSegment.Offset + _charSegment.Length / 2]; + return _charSegment.Contains(searchChar); + } + + [Benchmark] + public bool SegmentContains() + { + char searchChar = _data[_segment.Offset + _segment.Length / 2]; + return _segment.Contains(searchChar); + } + + [Benchmark] + public int CharSegmentIndexOf() + { + char searchChar = _data[_charSegment.Offset + _charSegment.Length / 2]; + return _charSegment.IndexOf(searchChar); + } + + [Benchmark] + public int SegmentIndexOf() + { + char searchChar = _data[_segment.Offset + _segment.Length / 2]; + return _segment.IndexOf(searchChar); + } + + [Benchmark] + public char[] CharSegmentToArray() => _charSegment.ToArray(); + + [Benchmark] + public char[] SegmentToArray() => _segment.ToArray(); + + [Benchmark] + public List CharSegmentToList() => _charSegment.ToList(); + + [Benchmark] + public List SegmentToList() => _segment.ToList(); + + [Benchmark] + public void CharSegmentForeachIteration() + { + foreach (var c in _charSegment) + { + // Empty loop to measure iteration overhead + } + } + + [Benchmark] + public void SegmentForeachIteration() + { + foreach (var c in _segment) + { + // Empty loop to measure iteration overhead + } + } + } +} \ No newline at end of file From f282c3cfa9859080e3de0482daafe737a38f0c72 Mon Sep 17 00:00:00 2001 From: konard Date: Sun, 14 Sep 2025 07:29:36 +0300 Subject: [PATCH 3/3] Remove CLAUDE.md - Claude command completed --- CLAUDE.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index 9cc864b5..00000000 --- a/CLAUDE.md +++ /dev/null @@ -1,5 +0,0 @@ -Issue to solve: https://github.com/linksplatform/Collections/issues/56 -Your prepared branch: issue-56-e9dd2c77 -Your prepared working directory: /tmp/gh-issue-solver-1757823859092 - -Proceed. \ No newline at end of file