Skip to content

Instantly share code, notes, and snippets.

@buybackoff
Created December 12, 2013 21:10
Show Gist options
  • Save buybackoff/ee57b2fe5919448b9b2b to your computer and use it in GitHub Desktop.
Save buybackoff/ee57b2fe5919448b9b2b to your computer and use it in GitHub Desktop.
PHM vs AVL
module PHMvsMapTree
open System
open System.Data
open System.Diagnostics
open NUnit.Framework
open Spreads.Collections
open Microsoft.FSharp.Collections
open FSharpx.Collections.Experimental
[<Test>]
let ``Could insert and lookup values gist``() =
let lim = 1000000L
let mutable phm = FSharpx.Collections.PersistentHashMap.Empty()
let mutable map = Map.empty
let watch = Stopwatch.StartNew();
for i in 0L..lim do
//map <- Map.add (i.ToString()) i map
phm <- FSharpx.Collections.PersistentHashMap.add (i) i phm
watch.Stop()
Console.WriteLine(">Inserts per sec: " + (1000L * int64(lim)/watch.ElapsedMilliseconds).ToString())
let watch1 = Stopwatch.StartNew();
let mutable res = Some 0L
for i in 0L..lim do
//res <- Some( Map.find (i.ToString()) map)
res <- Some (FSharpx.Collections.PersistentHashMap.find (i) phm)
watch1.Stop()
Console.WriteLine(">Lookup per sec: " + (1000L * int64(lim)/watch1.ElapsedMilliseconds).ToString())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment