Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions QuadTree.Benchmark/Exists.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
namespace QuadTree.Benchmarks.Exists


open BenchmarkDotNet.Attributes
open QuadTree.Benchmarks.Utils

[<Config(typeof<MyConfig>)>]
type Benchmark() =

let mutable denseVec = Unchecked.defaultof<Vector.SparseVector<int>>
let mutable sparseVec = Unchecked.defaultof<Vector.SparseVector<int>>
let mutable denseMat = Unchecked.defaultof<Matrix.SparseMatrix<int>>
let mutable sparseMat = Unchecked.defaultof<Matrix.SparseMatrix<int>>

[<Params(64, 256, 1024)>]
member val N = 0 with get, set

[<GlobalSetup>]
member this.Setup() =
let denseData =
[ for i in 0UL .. uint64 this.N - 1UL -> (i * 1UL<Vector.index>, int i % 100) ]

denseVec <- Vector.fromCoordinateList (Vector.CoordinateList(uint64 this.N * 1UL<Vector.dataLength>, denseData))

let sparseData =
[ for i in 0UL .. 10UL .. uint64 this.N - 1UL -> (i * 1UL<Vector.index>, int i % 100) ]

sparseVec <-
Vector.fromCoordinateList (Vector.CoordinateList(uint64 this.N * 1UL<Vector.dataLength>, sparseData))

let denseMatData =
[ for r in 0UL .. uint64 this.N - 1UL do
for c in 0UL .. uint64 this.N - 1UL do
(r * 1UL<Matrix.rowindex>, c * 1UL<Matrix.colindex>, int (r + c) % 100) ]

denseMat <-
Matrix.fromCoordinateList (
Matrix.CoordinateList(
uint64 this.N * 1UL<Matrix.nrows>,
uint64 this.N * 1UL<Matrix.ncols>,
denseMatData
)
)

let sparseMatData =
[ for r in 0UL .. 10UL .. uint64 this.N - 1UL do
for c in 0UL .. 10UL .. uint64 this.N - 1UL do
(r * 1UL<Matrix.rowindex>, c * 1UL<Matrix.colindex>, int (r + c) % 100) ]

sparseMat <-
Matrix.fromCoordinateList (
Matrix.CoordinateList(
uint64 this.N * 1UL<Matrix.nrows>,
uint64 this.N * 1UL<Matrix.ncols>,
sparseMatData
)
)

[<Benchmark>]
member this.VectorExistsDense() = Vector.exists denseVec (fun x -> x < 0)

[<Benchmark>]
member this.VectorExistsSparse() =
Vector.exists sparseVec (fun x -> x < 0)

[<Benchmark>]
member this.MatrixExistsDense() = Matrix.exists denseMat (fun x -> x < 0)

[<Benchmark>]
member this.MatrixExistsSparse() =
Matrix.exists sparseMat (fun x -> x < 0)
72 changes: 72 additions & 0 deletions QuadTree.Benchmark/Filters.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
namespace QuadTree.Benchmarks.Filters

open BenchmarkDotNet.Attributes
open QuadTree.Benchmarks.Utils

[<Config(typeof<MyConfig>)>]
type Benchmark() =

let mutable denseVec = Unchecked.defaultof<Vector.SparseVector<int>>
let mutable sparseVec = Unchecked.defaultof<Vector.SparseVector<int>>
let mutable denseMat = Unchecked.defaultof<Matrix.SparseMatrix<int>>
let mutable sparseMat = Unchecked.defaultof<Matrix.SparseMatrix<int>>

[<Params(64, 256, 1024)>]
member val N = 0 with get, set

[<GlobalSetup>]
member this.Setup() =
let denseData =
[ for i in 0UL .. uint64 this.N - 1UL -> (i * 1UL<Vector.index>, int i % 100) ]

denseVec <- Vector.fromCoordinateList (Vector.CoordinateList(uint64 this.N * 1UL<Vector.dataLength>, denseData))

let sparseData =
[ for i in 0UL .. 10UL .. uint64 this.N - 1UL -> (i * 1UL<Vector.index>, int i % 100) ]

sparseVec <-
Vector.fromCoordinateList (Vector.CoordinateList(uint64 this.N * 1UL<Vector.dataLength>, sparseData))

let denseMatData =
[ for r in 0UL .. uint64 this.N - 1UL do
for c in 0UL .. uint64 this.N - 1UL do
(r * 1UL<Matrix.rowindex>, c * 1UL<Matrix.colindex>, int (r + c) % 100) ]

denseMat <-
Matrix.fromCoordinateList (
Matrix.CoordinateList(
uint64 this.N * 1UL<Matrix.nrows>,
uint64 this.N * 1UL<Matrix.ncols>,
denseMatData
)
)

let sparseMatData =
[ for r in 0UL .. 10UL .. uint64 this.N - 1UL do
for c in 0UL .. 10UL .. uint64 this.N - 1UL do
(r * 1UL<Matrix.rowindex>, c * 1UL<Matrix.colindex>, int (r + c) % 100) ]

sparseMat <-
Matrix.fromCoordinateList (
Matrix.CoordinateList(
uint64 this.N * 1UL<Matrix.nrows>,
uint64 this.N * 1UL<Matrix.ncols>,
sparseMatData
)
)

[<Benchmark>]
member this.VectorFilterDense() =
Vector.filter denseVec (fun x -> x % 2 = 0)

[<Benchmark>]
member this.VectorFilterSparse() =
Vector.filter sparseVec (fun x -> x % 2 = 0)

[<Benchmark>]
member this.MatrixFilterDense() =
Matrix.filter denseMat (fun x -> x % 2 = 0)

[<Benchmark>]
member this.MatrixFilterSparse() =
Matrix.filter sparseMat (fun x -> x % 2 = 0)
73 changes: 73 additions & 0 deletions QuadTree.Benchmark/Forall.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace QuadTree.Benchmarks.Forall


open BenchmarkDotNet.Attributes
open QuadTree.Benchmarks.Utils

[<Config(typeof<MyConfig>)>]
type Benchmark() =

let mutable denseVec = Unchecked.defaultof<Vector.SparseVector<int>>
let mutable sparseVec = Unchecked.defaultof<Vector.SparseVector<int>>
let mutable denseMat = Unchecked.defaultof<Matrix.SparseMatrix<int>>
let mutable sparseMat = Unchecked.defaultof<Matrix.SparseMatrix<int>>

[<Params(64, 256, 1024)>]
member val N = 0 with get, set

[<GlobalSetup>]
member this.Setup() =
let denseData =
[ for i in 0UL .. uint64 this.N - 1UL -> (i * 1UL<Vector.index>, int i % 100) ]

denseVec <- Vector.fromCoordinateList (Vector.CoordinateList(uint64 this.N * 1UL<Vector.dataLength>, denseData))

let sparseData =
[ for i in 0UL .. 10UL .. uint64 this.N - 1UL -> (i * 1UL<Vector.index>, int i % 100) ]

sparseVec <-
Vector.fromCoordinateList (Vector.CoordinateList(uint64 this.N * 1UL<Vector.dataLength>, sparseData))

let denseMatData =
[ for r in 0UL .. uint64 this.N - 1UL do
for c in 0UL .. uint64 this.N - 1UL do
(r * 1UL<Matrix.rowindex>, c * 1UL<Matrix.colindex>, int (r + c) % 100) ]

denseMat <-
Matrix.fromCoordinateList (
Matrix.CoordinateList(
uint64 this.N * 1UL<Matrix.nrows>,
uint64 this.N * 1UL<Matrix.ncols>,
denseMatData
)
)

let sparseMatData =
[ for r in 0UL .. 10UL .. uint64 this.N - 1UL do
for c in 0UL .. 10UL .. uint64 this.N - 1UL do
(r * 1UL<Matrix.rowindex>, c * 1UL<Matrix.colindex>, int (r + c) % 100) ]

sparseMat <-
Matrix.fromCoordinateList (
Matrix.CoordinateList(
uint64 this.N * 1UL<Matrix.nrows>,
uint64 this.N * 1UL<Matrix.ncols>,
sparseMatData
)
)

[<Benchmark>]
member this.VectorForallDense() =
Vector.forall denseVec (fun x -> x >= 0)

[<Benchmark>]
member this.VectorForallSparse() =
Vector.forall sparseVec (fun x -> x >= 0)

[<Benchmark>]
member this.MatrixForallDense() =
Matrix.forall denseMat (fun x -> x >= 0)

[<Benchmark>]
member this.MatrixForallSparse() =
Matrix.forall sparseMat (fun x -> x >= 0)
5 changes: 4 additions & 1 deletion QuadTree.Benchmark/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ open BenchmarkDotNet.Running
let main argv =
let benchmarks =
BenchmarkSwitcher
[| typeof<QuadTree.Benchmarks.BFS.Benchmark>
[| typeof<QuadTree.Benchmarks.Filters.Benchmark>
typeof<QuadTree.Benchmarks.Exists.Benchmark>
typeof<QuadTree.Benchmarks.Forall.Benchmark>
typeof<QuadTree.Benchmarks.BFS.Benchmark>
typeof<QuadTree.Benchmarks.SSSP.Benchmark>
typeof<QuadTree.Benchmarks.Triangles.Benchmark> |]

Expand Down
3 changes: 3 additions & 0 deletions QuadTree.Benchmark/QuadTree.Benchmark.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

<ItemGroup>
<Compile Include="Utils.fs"/>
<Compile Include="Filters.fs"/>
<Compile Include="Exists.fs"/>
<Compile Include="Forall.fs"/>
<Compile Include="BFS.fs"/>
<Compile Include="SSSP.fs"/>
<Compile Include="Triangles.fs"/>
Expand Down
Loading
Loading