Skip to content

Instantly share code, notes, and snippets.

Created Dec 29, 2012

What would you like to do?
F# inline and effects on performance
open System
open System.Collections.Generic
type Pair<'a when 'a: equality> =
val v: 'a
val w: 'a
new(x,y)= {v=x;w=y}
let pair x y = new Pair<int>(x,y)
let inline Eq_cmp<'a when 'a: equality> = {
new IEqualityComparer<Pair<'a>> with
member x.Equals(a, b) =
(a.v = b.v) && (a.w = b.w)
member x.GetHashCode(y) =
let mutable h = 17 in
h <- y.v.GetHashCode()+(h*23);
h <- y.w.GetHashCode()+(h*23);
let perf_run i =
let c = Eq_cmp<int> in
let map = new Dictionary<_ , _>(10000000,c)
for j=0 to i do
map.Add((pair j (j*23^^^i)), i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.