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.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
@manofstick
manofstick / performance.fs
Created October 25, 2016 08:44
Seq Performance Various Sources
open System.Diagnostics
let createSources size f = [
"array", (lazy (Array.init size f :> seq<_>))
"list", (lazy (List.init size f :> seq<_>))
"computation expression", (lazy (seq {
let mutable x = 0
while x < size do
@manofstick
manofstick / seq.fs
Created November 1, 2016 08:08
Backup of SeqComposer
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.FSharp.Collections
#nowarn "52" // The value has been copied to ensure the original is not mutated by this operation
open System
open System.Diagnostics
open System.Collections
open System.Collections.Generic
open Microsoft.FSharp.Core