Skip to content

Commit

Permalink
Showing that lookups are slower - references #2
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Dec 10, 2013
1 parent ffa1d57 commit 5d578a2
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions help/PersistentHashMap.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,46 @@ let initFSharpMapAndPersistentMapFromList n =
" Multiple PersistentHashMap.add" (fun () -> initpersistentmap list)
" PersistentHashMap.ofSeq" (fun () -> ofSeq list)

let lookupInFSharpMapAndPersistentMap n count =
sprintf "%d Lookups in size n = %d" count n |> printInFsiTags
let list = [for i in 0..n-1 -> i,r.Next().ToString()]
let fsharpMap = Map.ofSeq list
let map = ofSeq list

compareTwoRuntimes trials
" FSharp.Map" (fun () -> for i in 1..count do fsharpMap.[r.Next n] |> ignore)
" PersistentHashMap" (fun () -> for i in 1..count do map.[r.Next n] |> ignore)

initFSharpMapAndPersistentMapFromList 10000
initFSharpMapAndPersistentMapFromList 100000
initFSharpMapAndPersistentMapFromList 1000000

lookupInFSharpMapAndPersistentMap 10000 10000
lookupInFSharpMapAndPersistentMap 100000 10000
lookupInFSharpMapAndPersistentMap 1000000 10000
lookupInFSharpMapAndPersistentMap 10000000 10000

// [fsi:Init with n = 10000]
// [fsi: FSharp.Map.ofSeq 25.2ms]
// [fsi: Multiple PersistentHashMap.add 22.4ms]
// [fsi: PersistentHashMap.ofSeq 12.2ms]
// [fsi: FSharp.Map.ofSeq 25.0ms]
// [fsi: Multiple PersistentHashMap.add 30.0ms]
// [fsi: PersistentHashMap.ofSeq 15.4ms]
// [fsi:Init with n = 100000]
// [fsi: FSharp.Map.ofSeq 260.6ms]
// [fsi: Multiple PersistentHashMap.add 309.8ms]
// [fsi: PersistentHashMap.ofSeq 214.0ms]
// [fsi: FSharp.Map.ofSeq 262.4ms]
// [fsi: Multiple PersistentHashMap.add 285.6ms]
// [fsi: PersistentHashMap.ofSeq 203.4ms]
// [fsi:Init with n = 1000000]
// [fsi: FSharp.Map.ofSeq 4955.6ms]
// [fsi: Multiple PersistentHashMap.add 5770.4ms]
// [fsi: PersistentHashMap.ofSeq 3867.6ms]
// [fsi: FSharp.Map.ofSeq 5284.2ms]
// [fsi: Multiple PersistentHashMap.add 6033.4ms]
// [fsi: PersistentHashMap.ofSeq 3919.4ms]
// [fsi:10000 Lookups in size n = 10000]
// [fsi: FSharp.Map 2.4ms]
// [fsi: PersistentHashMap 8.4ms]
// [fsi:10000 Lookups in size n = 100000]
// [fsi: FSharp.Map 3.2ms]
// [fsi: PersistentHashMap 8.6ms]
// [fsi:10000 Lookups in size n = 1000000]
// [fsi: FSharp.Map 7.0ms]
// [fsi: PersistentHashMap 12.4ms]
// [fsi:10000 Lookups in size n = 10000000]
// [fsi: FSharp.Map 12.2ms]
// [fsi: PersistentHashMap 15.6ms]

0 comments on commit 5d578a2

Please sign in to comment.