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'
.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
@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
@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 =