-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
232 additions
and
84 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...marks/Falko.Talkie.Benchmarks.Sequences/Benchmarks/FrozenSequenceForEachAsyncBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Engines; | ||
using Talkie.Models; | ||
using Talkie.Sequences; | ||
|
||
namespace Talkie.Benchmarks.Benchmarks; | ||
|
||
[SimpleJob(RunStrategy.Throughput)] | ||
public class FrozenSequenceForEachAsyncBenchmark | ||
{ | ||
private const int IterationsCount = 10; | ||
|
||
private readonly FrozenSequence<Reference> _frozenSequence = new(Enumerable.Repeat(Reference.Shared, IterationsCount)); | ||
|
||
[Benchmark] | ||
public async Task FrozenSequenceEnumerableWrapperForEach() | ||
{ | ||
foreach (var reference in _frozenSequence.AsEnumerable()) _ = reference; | ||
|
||
await Task.CompletedTask; | ||
} | ||
|
||
[Benchmark] | ||
public async Task FrozenSequenceEnumerableCastForEach() | ||
{ | ||
foreach (var reference in (IEnumerable<Reference>)_frozenSequence) _ = reference; | ||
|
||
await Task.CompletedTask; | ||
} | ||
|
||
[Benchmark] | ||
public async Task FrozenSequenceExtensionsForEach() | ||
{ | ||
_frozenSequence.ForEach(reference => _ = reference); | ||
|
||
await Task.CompletedTask; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Benchmarks/Falko.Talkie.Benchmarks.Sequences/Benchmarks/FrozenSequenceForEachBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Engines; | ||
using Talkie.Models; | ||
using Talkie.Sequences; | ||
|
||
namespace Talkie.Benchmarks.Benchmarks; | ||
|
||
[SimpleJob(RunStrategy.Throughput)] | ||
public class FrozenSequenceForEachBenchmark | ||
{ | ||
private const int IterationsCount = 10; | ||
|
||
private readonly FrozenSequence<Reference> _frozenSequence = new(Enumerable.Repeat(Reference.Shared, IterationsCount)); | ||
|
||
[Benchmark] | ||
public void FrozenSequenceStructForEach() | ||
{ | ||
foreach (var reference in _frozenSequence) _ = reference; | ||
} | ||
|
||
[Benchmark] | ||
public void FrozenSequenceEnumerableWrapperForEach() | ||
{ | ||
foreach (var reference in _frozenSequence.AsEnumerable()) _ = reference; | ||
} | ||
|
||
[Benchmark] | ||
public void FrozenSequenceEnumerableCastForEach() | ||
{ | ||
foreach (var reference in (IEnumerable<Reference>)_frozenSequence) _ = reference; | ||
} | ||
|
||
[Benchmark] | ||
public void FrozenSequenceMemoryForEach() | ||
{ | ||
foreach (var reference in _frozenSequence.AsMemory().Span) _ = reference; | ||
} | ||
|
||
[Benchmark] | ||
public void FrozenSequenceSpanForEach() | ||
{ | ||
foreach (var reference in _frozenSequence.AsSpan()) _ = reference; | ||
} | ||
|
||
[Benchmark] | ||
public void FrozenSequenceExtensionsForEach() | ||
{ | ||
_frozenSequence.ForEach(reference => _ = reference); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
using BenchmarkDotNet.Running; | ||
using Talkie.Benchmarks.Benchmarks; | ||
|
||
BenchmarkRunner.Run<AddBenchmark>(); | ||
BenchmarkRunner.Run<FirstAndLastBenchmark>(); | ||
BenchmarkRunner.Run<RemoveBenchmark>(); | ||
BenchmarkRunner.Run<ForeachBenchmark>(); | ||
BenchmarkRunner.Run<FrozenSequenceForEachAsyncBenchmark>(); | ||
BenchmarkRunner.Run<FrozenSequenceForEachBenchmark>(); | ||
BenchmarkRunner.Run<SequencesVsOtherFirstAndLastBenchmark>(); | ||
BenchmarkRunner.Run<SequencesVsOtherAddBenchmark>(); | ||
BenchmarkRunner.Run<SequencesVsOtherRemoveBenchmark>(); | ||
BenchmarkRunner.Run<SequencesVsOtherForEachBenchmark>(); |
28 changes: 28 additions & 0 deletions
28
Sources/Falko.Talkie.Core/Sequences/FrozenSequence.Enumerable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Talkie.Sequences; | ||
|
||
public partial class FrozenSequence<T> | ||
{ | ||
public readonly struct Enumerable : IEnumerable<T> | ||
{ | ||
private readonly T[] _values; | ||
|
||
private readonly int _valuesCount; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal Enumerable(T[] values, int valuesCount) | ||
{ | ||
_values = values; | ||
_valuesCount = valuesCount; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public IEnumerator<T> GetEnumerator() => new Enumerator(_values, _valuesCount); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
IEnumerator IEnumerable.GetEnumerator() => new Enumerator(_values, _valuesCount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.