Skip to content

Instantly share code, notes, and snippets.

View chrisa23's full-sized avatar

Chris Anderson chrisa23

  • CA Anderson LLC
  • Austin, TX
View GitHub Profile
@chrisa23
chrisa23 / data_performance.md
Created January 16, 2017 20:11 — forked from mrange/data_performance.md
On the topic of data locality and performance

On the topic of data locality and performance

Full source code can be found here

It is well-known that a hard disk has a long delay from that we request the data to that we get the data. Usually we measure the hard disk latency in milliseconds which is an eternity for a CPU. The bandwidth of a hard disk is decent good as SSD:s today can reach 1 GiB/second.

What is less known is that RAM has the same characteristics, bad latency with good bandwidth.

You can measure RAM latency and badndwidth using Intel® Memory Latency Checker. On my machine the RAM latency under semi-high load is ~120 ns (The 3r:1w bandwidth is 16GiB/second). This means that the CPU on my machine has to wait for ~400 cycles for data, an eternity.

@chrisa23
chrisa23 / StateMachine.fsx
Created June 5, 2016 22:57 — forked from taimila/StateMachine.fsx
Dynamic recursive API in F#
[<AutoOpen>]
module StateMachine =
type State =
| StateA
| StateB
| StateC
| StateD
| End
//==========================================
// Working fully self-contained getting-started example for Suave Web Server scripting
//
// Note you don't need to have _anything_ installed before starting with this script. Nothing
// but F# Interactive and this script.
//
// This script fetches the Paket.exe component which is referenced later in the script.
// Initially the #r "paket.exe" reference is shown as unresolved. Once it has been
// downloaded by the user (by executing the first part of the script) the reference
// shows as resolved and can be used.
@chrisa23
chrisa23 / gist:c04a1f8f421a031711f4
Created November 17, 2015 15:38 — forked from dsyme/gist:9b18608b78dccf92ba33
Working self-contained getting-started sample for Suave Web Scripting
//==========================================
// Working fully self-contained getting-started example for Suave Web Server scripting
//
// Note you don't need to have _anything_ installed before starting with this script. Nothing
// but F# Interactive and this script.
//
// This script fetches the Paket.exe component which is referenced later in the script.
// Initially the #r "paket.exe" reference is shown as unresolved. Once it has been
// downloaded by the user (by executing the first part of the script) the reference
// shows as resolved and can be used.
/// <summary>
/// Wrapper for GDI text rendering functions<br/>
/// This class is not thread-safe as GDI function should be called from the UI thread.
/// </summary>
/// <remarks>
/// http://theartofdev.com/2013/08/12/using-native-gdi-for-text-rendering-in-c/<br/>
/// The MIT License (MIT) Copyright (c) 2014 Arthur Teplitzki.
/// </remarks>
public sealed class NativeTextRenderer : IDisposable
{
open System
/// A fake logger type.
type Logger =
private { __ : unit }
[<RequireQualifiedAccess; CompilationRepresentation (CompilationRepresentationFlags.ModuleSuffix)>]
module Logger =
let info (_ : string) (_ : Logger) = ()
let warn (_ : string) (_ : Logger) = ()
/// A tic-tac-toe piece, or the absence thereof.
type Piece = U | X | O
/// Tic-tac-toe board position.
type Position = { X : int; Y : int }
/// A tic-tac-toe game implemented as a Pure ADT.
type Game =
private
{ FirstPlayerTurn : bool
open FSharpx.State
/// A tic-tac-toe piece, or the absence thereof.
type Piece = U | X | O
/// Tic-tac-toe board position.
type Position = { X : int; Y : int }
/// A tic-tac-toe game implemented as a Pure ADT.
type Game =
open System
open FSharpx.Reader
/// A fake logger type.
type Logger =
private { __ : unit }
[<RequireQualifiedAccess; CompilationRepresentation (CompilationRepresentationFlags.ModuleSuffix)>]
module Logger =
let info (_ : string) (_ : Logger) = ()
@chrisa23
chrisa23 / Pure ADT
Last active August 29, 2015 14:22 — forked from bryanedds/Pure ADT.fs
/// A tic-tac-toe piece, or the absence thereof.
type Piece = U | X | O
/// Tic-tac-toe board position.
type Position = { X : int; Y : int }
/// A tic-tac-toe game implemented as a Pure ADT.
type Game =
private
{ FirstPlayerTurn : bool