Skip to content

Commit

Permalink
Showing init stats for BCL.Dictionary - references #2
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Dec 10, 2013
1 parent c48b5f8 commit 319cd91
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 30 deletions.
1 change: 1 addition & 0 deletions .nuget/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit.Runners" version="2.6.3" />
<package id="Microsoft.Bcl.Immutable" version="1.0.30" targetFramework="net45" />
</packages>
47 changes: 29 additions & 18 deletions help/PersistentHashMap.fsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(*** hide ***)
#r "../build/FSharpx.Collections.dll"
#r "../lib/System.Runtime.dll"
#r "../packages/Microsoft.Bcl.Immutable.1.0.30/lib/portable-net45+win8+wp8/System.Collections.Immutable.dll"
open System


Expand Down Expand Up @@ -89,28 +91,34 @@ open FSharpx.Collections.TimeMeasurement

let initFSharpMapAndPersistentMapFromList n =
sprintf "Init with n = %d" n |> printInFsiTags
let list = [for i in 1..n -> r.Next(),r.Next().ToString()]

let list = List.sortBy snd [for i in 1..n -> i,r.Next().ToString()]

let initpersistentmap list =
let initPersistentHashMap list =
let m = ref empty
for (key,value) in list do
m := add key value !m
!m

compareThreeRuntimes trials
" FSharp.Map.ofSeq" (fun () -> Map.ofSeq list)
" Multiple PersistentHashMap.add" (fun () -> initpersistentmap list)
" PersistentHashMap.ofSeq" (fun () -> ofSeq list)
let initImmutableDictionary list =
let d = ref (System.Collections.Immutable.ImmutableDictionary<int,string>.Empty)
for (key,value) in list do
d := (!d).Add(key,value)
!d

stopAndReportAvarageTime trials " FSharp.Map.ofSeq" (fun () -> Map.ofSeq list) |> ignore
stopAndReportAvarageTime trials " Multiple PersistentHashMap.add" (fun () -> initPersistentHashMap list) |> ignore
stopAndReportAvarageTime trials " PersistentHashMap.ofSeq" (fun () -> ofSeq list) |> ignore
stopAndReportAvarageTime trials " Multiple ImmutableDictionay.add" (fun () -> initImmutableDictionary list) |> ignore

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

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

initFSharpMapAndPersistentMapFromList 10000
initFSharpMapAndPersistentMapFromList 100000
Expand All @@ -122,17 +130,20 @@ lookupInFSharpMapAndPersistentMap 1000000 10000
lookupInFSharpMapAndPersistentMap 10000000 10000

// [fsi:Init with n = 10000]
// [fsi: FSharp.Map.ofSeq 14.4ms]
// [fsi: Multiple PersistentHashMap.add 20.2ms]
// [fsi: PersistentHashMap.ofSeq 11.6ms]
// [fsi: FSharp.Map.ofSeq 22.4ms]
// [fsi: Multiple PersistentHashMap.add 19.4ms]
// [fsi: PersistentHashMap.ofSeq 12.6ms]
// [fsi: Multiple ImmutableDictionay.add 28.4ms]
// [fsi:Init with n = 100000]
// [fsi: FSharp.Map.ofSeq 238.8ms]
// [fsi: Multiple PersistentHashMap.add 351.2ms]
// [fsi: PersistentHashMap.ofSeq 195.8ms]
// [fsi: FSharp.Map.ofSeq 254.4ms]
// [fsi: Multiple PersistentHashMap.add 273.6ms]
// [fsi: PersistentHashMap.ofSeq 197.6ms]
// [fsi: Multiple ImmutableDictionay.add 382.2ms]
// [fsi:Init with n = 1000000]
// [fsi: FSharp.Map.ofSeq 3760.6ms]
// [fsi: Multiple PersistentHashMap.add 5912.0ms]
// [fsi: PersistentHashMap.ofSeq 3680.2ms]
// [fsi: FSharp.Map.ofSeq 5145.2ms]
// [fsi: Multiple PersistentHashMap.add 5730.2ms]
// [fsi: PersistentHashMap.ofSeq 4392.4ms]
// [fsi: Multiple ImmutableDictionay.add 7035.6ms]
// [fsi:10000 Lookups in size n = 10000]
// [fsi: FSharp.Map 8.8ms]
// [fsi: PersistentHashMap 8.4ms]
Expand Down
7 changes: 3 additions & 4 deletions help/PersistentVector.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ let initArrayAndVectorFromList n =
v := conj x !v
!v

compareThreeRuntimes trials
" Array.ofSeq" (fun () -> Array.ofSeq list)
" Multiple PersistentVector.conj" (fun () -> initvector list)
" PersistentVector.ofSeq" (fun () -> ofSeq list)
stopAndReportAvarageTime trials " Array.ofSeq" (fun () -> Array.ofSeq list) |> ignore
stopAndReportAvarageTime trials " Multiple PersistentVector.conj" (fun () -> initvector list) |> ignore
stopAndReportAvarageTime trials " PersistentVector.ofSeq" (fun () -> ofSeq list) |> ignore

let lookupInArrayAndVector n count =
sprintf "%d Lookups in size n = %d" count n |> printInFsiTags
Expand Down
4 changes: 4 additions & 0 deletions help/csharp/csharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable">
<HintPath>..\..\packages\Microsoft.Bcl.Immutable.1.0.30\lib\portable-net45+win8+wp8\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -48,6 +51,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\app\FSharpx.Collections\FSharpx.Collections.fsproj">
Expand Down
4 changes: 4 additions & 0 deletions help/csharp/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl.Immutable" version="1.0.30" targetFramework="net45" />
</packages>
8 changes: 0 additions & 8 deletions src/app/FSharpx.Collections/Infrastructure.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,4 @@ let stopAndReportAvarageTime count desc f =
let compareTwoRuntimes count desc1 f1 desc2 f2 =
let _,time1 = stopAndReportAvarageTime count desc1 f1
let _,time2 = stopAndReportAvarageTime count desc2 f2
()

/// Stops the average runtime for the given functions
/// Afterwards it reports it with the given descriptions
let compareThreeRuntimes count desc1 f1 desc2 f2 desc3 f3 =
let _,time1 = stopAndReportAvarageTime count desc1 f1
let _,time2 = stopAndReportAvarageTime count desc2 f2
let _,time3 = stopAndReportAvarageTime count desc3 f3
()

0 comments on commit 319cd91

Please sign in to comment.