Skip to content

Instantly share code, notes, and snippets.

View i3arnon's full-sized avatar

Bar Arnon i3arnon

View GitHub Profile
@i3arnon
i3arnon / dotnetlayout.md
Created December 14, 2021 19:40 — forked from davidfowl/dotnetlayout.md
.NET project structure
$/
  artifacts/
  build/
  docs/
  lib/
  packages/
  samples/
  src/
 tests/
[MemoryDiagnoser]
public class Program
{
private const int NumberOfLabels = IPAddressParserStatics.IPv6AddressBytes / 2;
private static readonly uint ScopeId;
private static readonly ushort[] Numbers;
static Program()
{
var ipAddress = IPAddress.Parse("2001:4860:4860::8888");
public class Poller<TData>
{
private readonly Func<Task<TData>> _func;
private Task<TData> _task;
private int _hasData;
// Returns default values before first poll.
public TData Data { get; private set; }
public bool HasData => _hasData == 1;
public class Syncer<TKey, TResult>
{
private readonly ConcurrentDictionary<TKey, TaskCompletionSource<TResult>> _taskCompletionSources = new ConcurrentDictionary<TKey, TaskCompletionSource<TResult>>();
public Task<TResult> RunAsync(TKey key, Func<Task<TResult>> func)
{
var newTaskCompletionSource = new TaskCompletionSource<TResult>();
var existingTaskCompletionSource = _taskCompletionSources.GetOrAdd(key, newTaskCompletionSource);
if (newTaskCompletionSource == existingTaskCompletionSource)
{
// * Detailed results *
Program_GetSystemTimeAsFileTime
Mean = 15.0677 ns, StdError = 0.0775 ns (0.51%); N = 60, StdDev = 0.6000 ns
Min = 14.3962 ns, Q1 = 14.6196 ns, Median = 14.8500 ns, Q3 = 15.3732 ns, Max = 17.0593 ns
IQR = 0.7536 ns, LowerFence = 13.4891 ns, UpperFence = 16.5036 ns
ConfidenceInterval = [14.9159 ns; 15.2195 ns] (CI 95%)
Program_UtcNow
Mean = 5.0350 ns, StdError = 0.0096 ns (0.19%); N = 110, StdDev = 0.1007 ns
@i3arnon
i3arnon / 01-LogicalOperationStack-06.cs
Last active October 6, 2015 21:28
Fixed LogicalFlow using an ImmutableStack
public static class LogicalFlow
{
private static ImmutableStack<Guid> LogicalStack
{
get
{
return CallContext.LogicalGetData("LogicalFlow") as ImmutableStack<Guid> ?? ImmutableStack.Create<Guid>();
}
set
{
@i3arnon
i3arnon / 01-LogicalOperationStack-05.txt
Created October 6, 2015 21:25
Correct output when copying CallContext
00000000-0000-0000-0000-000000000000
fdc22318-53ef-4ae5-83ff-6c3e3864e37a
fdc22318-53ef-4ae5-83ff-6c3e3864e37a
fdc22318-53ef-4ae5-83ff-6c3e3864e37a
00000000-0000-0000-0000-000000000000
@i3arnon
i3arnon / 01-LogicalOperationStack-04.cs
Created October 6, 2015 21:24
Setting anything into the CallContext copies it
public static IDisposable StartScope()
{
CallContext.LogicalSetData("Bar", "Arnon");
Trace.CorrelationManager.StartLogicalOperation();
return new Stopper();
}
@i3arnon
i3arnon / 01-LogicalOperationStack-03.txt
Created October 6, 2015 21:22
Output using LogicalOperationStack
00000000-0000-0000-0000-000000000000
49985135-1e39-404c-834a-9f12026d9b65
54674452-e1c5-4b1b-91ed-6bd6ea725b98
c6ec00fd-bff8-4bde-bf70-e073b6714ae5
54674452-e1c5-4b1b-91ed-6bd6ea725b98
@i3arnon
i3arnon / 01-LogicalOperationStack-02.cs
Created October 6, 2015 21:21
LogicalFlow - A wrapper over LogicalOperationStack
public static class LogicalFlow
{
public static Guid CurrentOperationId
{
get
{
return Trace.CorrelationManager.LogicalOperationStack.Count > 0
? (Guid) Trace.CorrelationManager.LogicalOperationStack.Peek()
: Guid.Empty;
}