Skip to content

Instantly share code, notes, and snippets.

View john-h-k's full-sized avatar

John Kelly john-h-k

View GitHub Profile
from __future__ import annotations
from typing import List, TypeVar, Generic, Callable, Dict, Any, TextIO, Iterable, Tuple
from functools import wraps, partial
from dataclasses import dataclass
from enum import Enum
from copy import deepcopy
import re
import operator
import importlib
import os
internal unsafe sealed class Win32EventTaskSource : IValueTaskSource
{
private IntPtr _hEvent;
public Win32EventTaskSource(IntPtr hEvent) => _hEvent = hEvent;
public void GetResult(short token)
{
_ = WaitForSingleObject(_hEvent, 0) switch
{
public readonly struct GenerationalHandle
{
public readonly uint Generation;
public readonly uint Handle;
public GenerationalHandle(uint generation, uint handle)
{
Generation = generation;
Handle = handle;
}
public unsafe class FileSystemDictionary<TValue> : IDictionary<string, TValue>
{
private DirectoryInfo _directory;
public string Name { get; private set; }
public FileSystemDictionary(string? name = null)
{
Name = name ?? Guid.NewGuid().ToString();
_directory = Directory.CreateDirectory(Path.Join(Path.GetTempPath(), Name));
}
public class IsPow2Benchmark
{
private const int Iterations = 1024;
public int[] Values { get; } = new int[Iterations];
private volatile bool _result;
public enum DataType { Zero, Random, UniformPow2, UniformNonPow2, UniformNegative, Alternating, AlternatingSign }
[Params(DataType.Zero, DataType.Random, DataType.UniformPow2, DataType.UniformNonPow2, DataType.UniformNegative, DataType.Alternating, DataType.AlternatingSign)]
from enum import Enum
from random import choice
from typing import List
from tkinter import *
class PlayerState(Enum):
PLAYING = 0
LOST = 1
WIN = 2
fixed (int* pSrcA = &MemoryMarshal.GetArrayDataReference(a))
fixed (int* pSrcB = &MemoryMarshal.GetArrayDataReference(b))
fixed (int* pRes = &MemoryMarshal.GetArrayDataReference(res))
{
var alignedRes = (int*)(((ulong)pRes + 31) & ~31ul);
var diff = alignedRes - pRes;
// unaligned block
{
var block0 = Avx2.LoadVector256(pSrcA);
public class InvokeBenchmark
{
[Benchmark]
public void Native() => NativeDivDivDiv(uint.MaxValue, 15, 16, 55);
[DllImport(@"C:\Users\johnk\source\repos\InvokeBenchmarkNative.exe")]
[SuppressGCTransition]
public static extern uint NativeDivDivDiv(uint a, uint b, uint c, uint d);
[Benchmark]
@john-h-k
john-h-k / Pix.cpp
Created June 21, 2020 22:34
rough description of how i think PIX works
/*
* K, quick debrief on how PIX works cuz y'all gonna need to know to understand this codebase.
*
* I am certainly going to be wrong at least somwhere here. Please correct if you realise I am
*
* First and foremost, perf is absolutely critical here. Don't get clever and start optimising the generics
* with params object[]
*
* PIX has 2 types of events/markers