This file contains hidden or 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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFrameworks>net6.0;net7.0</TargetFrameworks> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="BenchmarkDotNet" /> |
This file contains hidden or 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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net6.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> |
This file contains hidden or 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
using System.Buffers; | |
namespace GenMath; | |
public static class Extensions | |
{ | |
public static TResult[] ToArray<TResult>(this Range range, Func<int, TResult> transformer) | |
{ | |
if (range.Start.IsFromEnd || range.End.IsFromEnd) throw new NotSupportedException("'FromEnd' ranges are not supported "); |
This file contains hidden or 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
using System.Numerics; | |
namespace Benchmarks; | |
readonly struct DoubleVector | |
{ | |
private readonly double[] _values; | |
public DoubleVector(double[] values) => _values = values; | |
public double Average() |
This file contains hidden or 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
var distances = Enumerable.Range(1, 10).Select(i => new Distance(i)).ToArray(); | |
var sumOfDistances = Sum(distances); | |
var times = Enumerable.Range(1, 10).Select(i => new Time(i * i)).ToArray(); | |
var velocities = distances.Zip(times).Select(pair => pair.First / pair.Second).ToArray(); | |
static TUnit Sum<TUnit>(IEnumerable<TUnit> units) | |
where TUnit : IUnit<TUnit> |
This file contains hidden or 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
var parsedLines = Lines<CommaSeparatedWords>.Parse(""" | |
Ala,has,a,cat | |
Cat,has,Ala | |
"""); | |
var parsedNumbers = CsvFile<int>.Parse(""" | |
11 | |
22 | |
33 | |
"""); |
This file contains hidden or 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
string[] symbolsUniverse = new[] { "AAPL", "VOD", "ADBE", "GRPN", "META", "ACER", "GOOG", "BP" }; | |
List<string> GenerateSymbols(int number) | |
{ | |
var symbols = new List<string>(); | |
for (int i = 0; i < symbolsUniverse.Length; i++) | |
{ | |
var bit = 1 << i; | |
if ((number & bit) == bit) | |
symbols.Add(symbolsUniverse[i]); | |
} |
This file contains hidden or 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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net6.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
</Project> |
This file contains hidden or 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
interface Changeable | |
infix fun <TTarget : Changeable, TProperty> Changeable.withChanged(change: Pair<kotlin.reflect.KProperty1<TTarget, TProperty>, TProperty>): Changeable = | |
this.also { | |
val (property, newValue) = change | |
val field = it::class.java.getDeclaredField(property.name) | |
field.isAccessible = true | |
field.set(it, newValue) | |
} |
This file contains hidden or 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
[TestCase(0, 0, "")] | |
[TestCase(1, 1, "3")] | |
[TestCase(2, 2, "3|4")] | |
[TestCase(3, 3, "3|4|5")] | |
[TestCase(4, 3, "3|4|5|0")] | |
[TestCase(5, 3, "3|4|5|0|0")] | |
public void Read_ToBuffer_ShouldBeAbleToReadBytes(int bufferSize, int expectedCount, string expectedArray) | |
{ | |
var sut = new SpanBinaryReader(new byte[] { 1, 2, 3, 4, 5 }, 2); | |
// ^ |