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 / EqualityComparesComparison.fs
Created July 25, 2015 19:39
Comparing NonStructural Comparer
module Program
open System
open System.Collections.Generic
open System.Diagnostics
let r = Random 42
let count = 1000000
let checkValueDate = DateTime (1980, 2, 18)
@manofstick
manofstick / priming_and_tuples.fs
Created July 31, 2015 10:02
Showing the initial "priming" time, and tuples
open System
open System.Diagnostics
let check<'a when 'a : equality>(x:'a, y:'a) =
for i=1 to 0 do failwith "this is just to stop f# inlining"
if x = y then 1 else 0
let count = 50000000
let tuple2 () =
@manofstick
manofstick / comparers.fs
Created August 5, 2015 10:01
The dynamic comparers generator
namespace Test
module HackedOutOfPrimTypes =
open System
open System.Collections
open System.Collections.Generic
open System.Reflection
open System.Runtime.CompilerServices
type KeyStruct(_1':int, _2':int, _3':int) = struct
member this._1 = _1'
member this._2 = _2'
member this._3 = _3'
end
type KeyGenericStruct<'a>(_1':'a, _2':'a, _3':'a) = struct
member this._1 = _1'
member this._2 = _2'
member this._3 = _3'
open Perf
open System
open System.Diagnostics
open System.IO
open System.Collections.Generic
let inline run<'key when 'key : equality> (comparer:IEqualityComparer<'key>) (createKey:int -> int -> 'key) =
let g_maxSize = 4480
let fileSizes = [ 1 .. 99 ]
.assembly hello {}
.class public auto ansi serializable beforefieldinit Library1.JumpBImpl`1<class (class [mscorlib]System.IEquatable`1<!a>) a>
extends [mscorlib]System.Object
{
.method public specialname rtspecialname
instance void .ctor () cil managed
{
.maxstack 8
let depth = 1000000
module Test =
let check basis createItem =
let rec createList n l =
if n = 0 then l
else createList (n-1) (createItem (int64 n, int64 n) l)
let a0 = createList depth basis
let a1 = createList depth basis
open System
open System.Threading
open System.Threading.Tasks
open System.Diagnostics
let bindBool (f: bool -> Task<bool>) (m: Task<bool>) =
if m.IsCompleted
then
f m.Result
else
open FSharp.Quotations
let rec getMethodInfo = function
| Patterns.Call(_,``method``,_) -> ``method``
| Patterns.Lambda(_,body) -> getMethodInfo body
| _ -> failwith "Unexpected Form"
let getGenericMethodInfo functionExpression =
let methodInfo = getMethodInfo functionExpression
if methodInfo.IsGenericMethod then
@manofstick
manofstick / string.fs
Created June 6, 2016 20:55
Example of string functions
module SomeNamespace.String
open System
open System.Globalization
let inline private safe s =
match s with
| null -> String.Empty
| _ -> s