- [<Fact>]
- member this.``Benchmark`` () =
- let min = -1_000.
- let max = +1_000.
- let windowSize = 10.
- let nbPoints = 500_000
- let n = 1_000
-
- let rng = System.Random 42
- let nextNumber (min : float) (max : float) =
- (rng.NextDouble () * (max + abs min)) + min |> float32
-
- let points =
- [
- for i = 1 to nbPoints do
- let x = nextNumber min max
- let y = nextNumber min max
- yield Point (x, y)
- ]
-
- let sw = System.Diagnostics.Stopwatch ()
- sw.Start ()
-
- let tree = Tree.BuildTree points
-
- sw.Stop ()
- output.WriteLine (sprintf "Time to build = %A ms" sw.ElapsedMilliseconds)
-
- sw.Restart ()
-
- let mutable nbFound = 0
- for i = 1 to n do
- let minX = nextNumber min (max - windowSize)
- let minY = nextNumber min (max - windowSize)
- nbFound <- nbFound + (tree.Search { minX = minX; maxX = minX + float32 windowSize; minY = minY; maxY = minY + float32 windowSize } |> List.length)
-
- sw.Stop ()
- output.WriteLine (sprintf "nb found: %i. Time to search = %A ms" nbFound sw.ElapsedMilliseconds)