public
anonymous / gist:4409734
Created

F# inline and effects on performance

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
open System
open System.Collections.Generic
 
[<Struct>]
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);
h
}
 
 
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.