Skip to content
Merged
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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ CodeCoverage/
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
nunit-*.xml

# Benchmarking results
BenchmarkDotNet.Artifacts/

# Matrices
*.mtx
25 changes: 25 additions & 0 deletions QuadTree.Benchmark/BFS.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace QuadTree.Benchmarks.BFS

open BenchmarkDotNet.Attributes
open QuadTree.Benchmarks.Utils

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

let mutable matrix = Unchecked.defaultof<Matrix.SparseMatrix<double>>


[<Params("494_bus.mtx", "arc130.mtx")>]
member val MatrixName = "" with get, set

[<GlobalSetup>]
member this.LoadMatrix() =
matrix <- readMtx (System.IO.Path.Combine(DIR_WITH_MATRICES, this.MatrixName)) false

[<Benchmark>]
member this.BFS() =
let startVertices =
Vector.CoordinateList((uint64 matrix.ncols) * 1UL<Vector.dataLength>, [ 0UL<Vector.index>, 1UL ])
|> Vector.fromCoordinateList

Graph.BFS.bfs_level matrix startVertices
12 changes: 12 additions & 0 deletions QuadTree.Benchmark/Main.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
open BenchmarkDotNet.Running

[<EntryPoint>]
let main argv =
let benchmarks =
BenchmarkSwitcher
[| typeof<QuadTree.Benchmarks.BFS.Benchmark>
typeof<QuadTree.Benchmarks.SSSP.Benchmark>
typeof<QuadTree.Benchmarks.Triangles.Benchmark> |]

benchmarks.Run argv |> ignore
0
25 changes: 25 additions & 0 deletions QuadTree.Benchmark/QuadTree.Benchmark.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<Compile Include="Utils.fs"/>
<Compile Include="BFS.fs"/>
<Compile Include="SSSP.fs"/>
<Compile Include="Triangles.fs"/>
<Compile Include="Main.fs"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\QuadTree\QuadTree.fsproj" />
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions QuadTree.Benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Benchmarks

Benchmarking infrastructure for
* [BFS](BFS.fs)
* [SSSP](SSSP.fs)
* [Triangles counting](Triangles.fs)

## Steps to run

1. Add ```*.mtx``` files to the [```data```](data/) directory. Do not commit these files. Several small matrices are included for demo purposes only.
2. Configure ```MatrixName``` in the respective ```.fs``` files: list the matrices to be used for evaluation in the ```Params``` attribute. For example: ```[<Params("494_bus.mtx", "arc130.mtx")>]``` in ```BFS.fs```.
```fsharp
[<Params("494_bus.mtx", "arc130.mtx")>]
member val MatrixName = "" with get, set
```
3. Ensure the matrix reader is correctly configured. In ```LoadMatrix ()``` , you can pass a boolean flag to ```readMtx``` indicating whether the matrix should be treated as a directed or undirected graph. Current configuration:
1. Undirected for ```BFS``` and ```Triangles counting```.
2. Directed for ```SSSP```.
4. Run evaluation: ```dotnet run -c Release -- --filter '*.SSSP.*'``` You can use ```--filter``` to specify particular benchmarks. Use ```--filter '*'``` to run all available benchmarks.
5. Raw benchmarking results are saved in ```BenchmarkDotNet.Artifacts/results/*.csv```.
19 changes: 19 additions & 0 deletions QuadTree.Benchmark/SSSP.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace QuadTree.Benchmarks.SSSP

open BenchmarkDotNet.Attributes
open QuadTree.Benchmarks.Utils

[<Config(typeof<MyConfig>)>]
type Benchmark() =
let mutable matrix = Unchecked.defaultof<Matrix.SparseMatrix<double>>


[<Params("494_bus.mtx", "arc130.mtx")>]
member val MatrixName = "" with get, set

[<GlobalSetup>]
member this.LoadMatrix() =
matrix <- readMtx (System.IO.Path.Combine(DIR_WITH_MATRICES, this.MatrixName)) true

[<Benchmark>]
member this.SSSP() = Graph.SSSP.sssp matrix 0UL
20 changes: 20 additions & 0 deletions QuadTree.Benchmark/Triangles.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace QuadTree.Benchmarks.Triangles

open BenchmarkDotNet.Attributes
open QuadTree.Benchmarks.Utils

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

let mutable matrix = Unchecked.defaultof<Matrix.SparseMatrix<double>>

[<Params("494_bus.mtx", "arc130.mtx")>]
member val MatrixName = "" with get, set

[<GlobalSetup>]
member this.LoadMatrix() =
matrix <- readMtx (System.IO.Path.Combine(DIR_WITH_MATRICES, this.MatrixName)) false

[<Benchmark>]
member this.TriangleCount() =
Graph.TriangleCount.triangle_count matrix
38 changes: 38 additions & 0 deletions QuadTree.Benchmark/Utils.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module QuadTree.Benchmarks.Utils

open System.IO
open BenchmarkDotNet.Configs

type MyConfig() =
inherit ManualConfig()

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

let readMtx path directed =
let getCooList (linewords: seq<string array>) =
linewords
|> Seq.map (fun x -> ((uint64 x.[0]) - 1UL), ((uint64 x.[1]) - 1UL), double x.[2])
|> Seq.collect (fun (i, j, v) ->
if not directed then
[ (i * 1UL<Matrix.rowindex>, j * 1UL<Matrix.colindex>, v)
(j * 1UL<Matrix.rowindex>, i * 1UL<Matrix.colindex>, v) ]
else
[ (i * 1UL<Matrix.rowindex>, j * 1UL<Matrix.colindex>, v) ])
|> List.ofSeq

let lines = File.ReadLines(path)
let removedComments = lines |> Seq.skipWhile (fun s -> s.[0] = '%')
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]

let tl = Seq.tail linewords

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

Matrix.CoordinateList(nrows * 1UL<Matrix.nrows>, nrows * 1UL<Matrix.ncols>, lst)
|> Matrix.fromCoordinateList
Loading
Loading