Skip to content

Instantly share code, notes, and snippets.

View Trapov's full-sized avatar
🏠
Working from home

dmitry afonin Trapov

🏠
Working from home
View GitHub Profile
@Trapov
Trapov / ForVsForeach.cs
Created May 5, 2019 11:44
ForVsForeach
namespace ForVsForeach
{
using System.Buffers;
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using System.Collections.Generic;
@Trapov
Trapov / ForVsForeach-Results.md
Created May 5, 2019 11:44
ForVsForeach-Results
BenchmarkDotNet=v0.11.5, OS=Windows 10.0.17763.475 (1809/October2018Update/Redstone5)
AMD A4-6300 APU with Radeon(tm) HD Graphics, 1 CPU, 2 logical cores and 1 physical core
.NET Core SDK=2.2.104
  [Host] : .NET Core 2.2.2 (CoreCLR 4.6.27317.07, CoreFX 4.6.27318.02), 64bit RyuJIT
  Core   : .NET Core 2.2.2 (CoreCLR 4.6.27317.07, CoreFX 4.6.27318.02), 64bit RyuJIT

Job=Core  Runtime=Core  
public sealed class CircullarList<T>
{
private readonly IReadOnlyList<T> _data;
public CircullarList(IReadOnlyList<T> data) => _data = data;
public T Current(in int index) => _data[index];
public T Next(in int index) => _data[index+1 % _data.Count];
public T Previous(in int index) => index-1 > 0 ? _data[index-1] : _data[_data.Count - 1];
}
class EntityHolder<TEntity> : IEntityHolder<TEntity>
where TEntity : IEntity, new()
{
public int Count { get; private set; }
public ushort TypeId { get; set; }
public Func<TEntity> EntityCreator { get; }
public EntityHolder(ushort typeId)
{
TypeId = typeId;