Skip to content

Instantly share code, notes, and snippets.

View manofstick's full-sized avatar

Paul Westcott manofstick

  • Kaiser Trading Group
  • Melbourne, Australia
View GitHub Profile
@manofstick
manofstick / filter_bench.fs
Created August 22, 2016 03:06
Benchmarking for Array.filter
/// BenchmarkDotNet Notes:
/// Docs/Github: https://github.com/PerfDotNet/BenchmarkDotNet#getting-started
///
/// This benchmarking suite will perform JIT warmups, collect system environment data
/// run multiple trials, and produce convenient reports.
/// You will find csv, markdown, and and html versions of the reports in .\BenchmarkDotNet.Artifacts\results
/// after running the tests.
///
/// Be sure to run tests in Release mode, optimizations on, etc.
@manofstick
manofstick / philter32.fs
Created August 23, 2016 04:12
Not very portable version of philter
module NotFastInBenchmarkDotNet
open System.Runtime.InteropServices
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE THAT THIS IS NOT PARTICULARLY PORTABLE, AS I'M RELYING ON PARTICULAR ENDIANNESS
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[<Struct; StructLayout (LayoutKind.Explicit); NoComparison; NoEquality>]
type private BoolToUint32 =
@manofstick
manofstick / filter.fs
Created August 24, 2016 04:59
Fast filtering
let boolToUInt32 (b:bool) = (# "conv.u4" (# "cgt.un" b 0 : int32 #) : uint32 #)
module internal Filter =
[<Struct; NoComparison; NoEquality>]
type MaskStruct =
val mutable _0x00 : bool
val mutable _0x01 : bool
val mutable _0x02 : bool
val mutable _0x03 : bool
@manofstick
manofstick / bit_counting.fs
Created August 24, 2016 05:09
Fast bit counting
module BitCountingAlgorithms =
let inline fastGetBitsCount (i:uint32) =
let mutable i = i - ((i >>> 1) &&& 0x55555555u)
i <- (i &&& 0x33333333u) + ((i >>> 2) &&& 0x33333333u)
(((i + (i >>> 4)) &&& 0x0F0F0F0Fu) * 0x01010101u) >>> 24
let safeGetBits (i:uint32) =
let mutable count = 0u
let mutable n = i
while n <> 0u do
let cli = new System.Net.WebClient ()
let data =
cli.DownloadString "https://raw.githubusercontent.com/dwyl/english-words/master/words.txt"
|> fun s -> s.Split ([|"\n"; "\r"; System.Environment.NewLine|], System.StringSplitOptions.None)
printfn "found %d words - shuffling" data.Length
let r = System.Random ()
for i = 0 to data.Length-1 do
let j = r.Next (i, data.Length-1)
@@ -65,7 +65,8 @@ type UnionReprDecisions<'Union,'Alt,'Type>
isStruct:'Union->bool,
nameOfAlt : 'Alt -> string,
makeRootType: 'Union -> 'Type,
makeNestedType: 'Union * string -> 'Type) =
makeNestedType: 'Union * string -> 'Type,
hasHelpers: 'Union->IlxUnionHasHelpers) =
static let TaggingThresholdFixedConstant = 4
open System.Collections.Generic
let validate = false
#if FROM_MAX
let lowerBound = System.Int32.MaxValue - 100000000
let upperBound = System.Int32.MaxValue
#else
#if FROM_MIN
let lowerBound = System.Int32.MinValue
open System
open System.IO
open System.Runtime.Serialization.Formatters.Binary
let filename = @"E:\binary";
let data = [
"This", 1
"is", 2
"just", 3
open BenchmarkDotNet.Running
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Diagnostics.Windows
open BenchmarkDotNet.Jobs
open System.Collections.Generic
open System.Collections
open System
@manofstick
manofstick / chunking.fs
Created October 24, 2016 02:46
Chunking vs Nessos.Streams
open System.Diagnostics
open Nessos.Streams
[<Struct; NoComparison; NoEquality>]
type Chunk<'T> =
[<DefaultValue false>] val mutable _toProcess : int
[<DefaultValue false>] val mutable _1 : 'T
[<DefaultValue false>] val mutable _2 : 'T
[<DefaultValue false>] val mutable _3 : 'T
[<DefaultValue false>] val mutable _4 : 'T