Skip to content

Instantly share code, notes, and snippets.

View LukasKastern's full-sized avatar

Lukas Kastern LukasKastern

View GitHub Profile
@garettbass
garettbass / type_map.zig
Created June 8, 2022 07:17
A generic type assigns an integer key to types at `comptime`, and allows values to be associated with the type at runtime.
const std = @import("std");
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Creates a named section in the binary, mapping concrete types to
/// monotonically increasing keys of integer or enum type.
/// The value associated with a type may be assigned at runtime, and queried
/// with the key assigned to that concrete type at `comptime`.
pub fn TypeMap(
comptime name: []const u8,
@cbaggers
cbaggers / NTuple.cs
Created January 9, 2022 20:35
ntuple thing
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Value Tuples that are blittable and so can be used in Unity's Jobs
// Replace with HashCode with System.HashCode when available
namespace Foo.Unmanaged
{
public static class NTuple
@jeffvella
jeffvella / BurstLogger.cs
Last active November 1, 2023 18:38
BurstLogger
// MIT LICENSE Copyright (c) 2020 Jeffrey Vella
// https://gist.github.com/jeffvella/dee1a82bd5edfcdc9d3067d8c038f95c/edit
using Unity.Burst;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Entities;
using Unity.Jobs.LowLevel.Unsafe;
using UnityEngine;
using System.Runtime.CompilerServices;
using Unity.Mathematics;
using Unity.Physics;
namespace NativeOctree
{
public struct Aabb4
{
public float4 MinXs;
public float4 MaxXs;
@distantcam
distantcam / JobHelper.cs
Last active August 17, 2023 15:54
Unity Job system with async
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Unity.Jobs;
public static class JobHelper
{
@yamnikov-oleg
yamnikov-oleg / LICENSE
Last active May 9, 2024 04:56
Shared (interprocess) mutexes on Linux
MIT License
Copyright (c) 2018 Oleg Yamnikov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@jboner
jboner / latency.txt
Last active May 23, 2024 06:51
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD