Created
December 29, 2012 22:32
-
-
Save anonymous/4409734 to your computer and use it in GitHub Desktop.
F# inline and effects on performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment