Created
October 29, 2012 18:55
-
-
Save pocketberserker/3975704 to your computer and use it in GitHub Desktop.
simple benchmarking BK-tree with Dictionary, Map and IntMap in F#
This file contains 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 FSharpx | |
let test () = | |
let rand = Random() | |
let list = Seq.init 20000 (fun _ -> rand.Next()) |> Seq.distinct |> Seq.toList | |
let d = 3 | |
let n = 1 | |
let t1 = DateTime.Now | |
let tree = list |> BKTree.Int.ofList | |
let t2 = DateTime.Now | |
tree |> BKTree.Int.toListDistance d n |> ignore | |
let t3 = DateTime.Now | |
tree |> BKTree.Int.existsDistance d n |> ignore | |
let t4 = DateTime.Now | |
(t2 - t1, t3 - t2, t4 - t3) | |
[| 1 .. 100 |] | |
|> Array.map (fun f -> test ()) | |
|> Array.map (fun (ofL,toLD,exD) -> (ofL.TotalMilliseconds, toLD.TotalMilliseconds, exD.TotalMilliseconds)) | |
|> Array.unzip3 | |
|> fun (ofL,toLD,exD) -> (Array.average ofL, Array.average toLD, Array.average exD) | |
|||> printfn "|BKTree | %12f | %12f | %12f |" |
This file contains 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
BKTree benchmark result(milli seconds) | |
----------------------------------------------------------------- | |
| | ofList |toListDistance|existsDistance| | |
|BKTree Map | 55.043146 | 57.293278 | 48.632783 | | |
|BKTree Dictionary | 13775.647916 | 12.030694 | 11.740671 | | |
|BKTree IntMap | 61.993548 | 0.060005 | 0.050001 | | |
----------------------------------------------------------------- | |
BKTree with Map -> https://github.com/fsharp/fsharpx/blob/5bcfc03c9062740832c881fadd4ec76da8112146/src/FSharpx.Core/DataStructures/BKTree.fs | |
BKTree with Dictionary -> https://github.com/fsharp/fsharpx/blob/de229f7cad652968e207c65ec0e8b0367a8d0b3b/src/FSharpx.Core/DataStructures/BKTree.fs | |
BKTree with IntMap -> https://github.com/pocketberserker/fsharpx/blob/dd32160e0afa77f433e668549b589e094a7b6793/src/FSharpx.Core/DataStructures/BKTree.fs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment