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)
10 changes: 8 additions & 2 deletions QuadTree.Benchmark/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ 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> |]
typeof<QuadTree.Benchmarks.Triangles.Benchmark>
typeof<QuadTree.Benchmarks.Formats.FormatBenchmark>
typeof<QuadTree.Benchmarks.Formats.DenseFormatBenchmark>
typeof<QuadTree.Benchmarks.RealMatrices.RealMatrixBenchmark> |]

benchmarks.Run argv |> ignore
0
5 changes: 5 additions & 0 deletions QuadTree.Benchmark/QuadTree.Benchmark.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@

<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"/>
<Compile Include="FormatBenchmarks.fs"/>
<Compile Include="RealMatrixBenchmark.fs"/>
<Compile Include="Main.fs"/>
</ItemGroup>

Expand Down
14 changes: 9 additions & 5 deletions QuadTree.Benchmark/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type MyConfig() =

let DIR_WITH_MATRICES = "../../../../../../../data/"

let readMtx path directed =
let readMtxRaw path directed =
let getCooList (linewords: seq<string array>) =
linewords
|> Seq.map (fun x ->
Expand All @@ -23,7 +23,7 @@ let readMtx path directed =

let lines = File.ReadLines(path)
let removedComments = lines |> Seq.skipWhile (fun s -> s.[0] = '%')
let linewords = removedComments |> Seq.map (fun s -> s.Split " ")
let linewords = removedComments |> Seq.map (fun s -> s.Split [|' '|])
let first = Seq.head linewords

let nrows, ncols, nnz = uint64 first.[0], uint64 first.[1], int first.[2]
Expand All @@ -33,7 +33,11 @@ let readMtx path directed =
let lst = getCooList tl

if (directed && nnz <> lst.Length) || ((not directed) && nnz * 2 <> lst.Length) then
failwithf "Incorrect matrix reading. Path: %A expected nnz: %A actual nnz: %A" path (nnz * 2) lst.Length
failwithf "Incorrect matrix reading. Path: %A expected nnz: %A actual nnz: %A" path (if directed then nnz else nnz * 2) lst.Length

let coo = Matrix.CoordinateList(nrows * 1UL<Matrix.nrows>, ncols * 1UL<Matrix.ncols>, lst)
let qt = Matrix.fromCoordinateList coo
(coo, qt)

Matrix.CoordinateList(nrows * 1UL<Matrix.nrows>, nrows * 1UL<Matrix.ncols>, lst)
|> Matrix.fromCoordinateList
let readMtx path directed =
readMtxRaw path directed |> snd
1 change: 1 addition & 0 deletions QuadTree.Tests/QuadTree.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ItemGroup>
<Compile Include="Tests.fs" />
<Compile Include="Tests.Vector.fs" />
<Compile Include="Tests.COO.fs" />
<Compile Include="Tests.Matrix.fs" />
<Compile Include="Tests.LinearAlgebra.fs" />
<Compile Include="Tests.BFS.fs" />
Expand Down
Loading