Skip to content

Instantly share code, notes, and snippets.

View gfoidl's full-sized avatar

Günther Foidl gfoidl

View GitHub Profile
@gfoidl
gfoidl / Custom_Partitioner_for_Parallel.ForEach_and_PLinq.cs
Last active December 30, 2017 20:41
Custom Partitioner for Parallel.ForEach and PLinq
//#define ORDER
//-----------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp1
{
@gfoidl
gfoidl / ThrowHelper_code.cs
Last active March 18, 2018 18:19
ThrowHelper
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ConsoleApplication
{
public unsafe class Program
@gfoidl
gfoidl / Struct_argument_code.cs
Last active January 22, 2018 10:00
Struct argument copy & byref
using System;
using System.Runtime.CompilerServices;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
var foo1 = new Foo1(1, 2, 3);
@gfoidl
gfoidl / Struct_field_readonly_code.cs
Created January 22, 2018 10:14
Struct readonly field
using System;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
var foo1 = new Foo1();
@gfoidl
gfoidl / Pointer_alignment.cs
Last active March 31, 2018 10:02
Pointer alignment
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace ConsoleApp1
{
class Program
{
static unsafe void Main(string[] args)
@gfoidl
gfoidl / Task_Action_continuation.cs
Created May 19, 2018 18:07
Task -> CancellationToken (benchmarks)
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Runtime.CompilerServices;
namespace ConsoleApp
{
class Program
{
@gfoidl
gfoidl / HW-Info.cs
Last active November 27, 2018 09:38
HW-Info
//#define REFLECTION_SCAN
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
#if REFLECTION_SCAN
using System.Linq;
#endif
@gfoidl
gfoidl / .NET Array cache line alignment length.cs
Last active October 30, 2020 15:21
.NET Array cache line alignment / length -- false sharing caution
using System;
using System.Linq;
namespace ConsoleApp3
{
static unsafe class Program
{
static void Main()
{
int[] arr = Enumerable.Range(2, 122).ToArray();