Skip to content

Commit b25bc97

Browse files
committed
refactor: benchmarks
1 parent 9e8b9bc commit b25bc97

16 files changed

Lines changed: 265 additions & 230 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace GraphBLAS.FSharp.Benchmarks
1+
namespace GraphBLAS.FSharp.Benchmarks.Algorithms
22

33
open System.IO
44
open BenchmarkDotNet.Attributes
@@ -15,8 +15,8 @@ open GraphBLAS.FSharp.Backend.Objects
1515
[<AbstractClass>]
1616
[<IterationCount(100)>]
1717
[<WarmupCount(10)>]
18-
[<Config(typeof<Configs.SingleMatrixConfig>)>]
19-
type BFSBenchmarks<'elem when 'elem : struct>(
18+
[<Config(typeof<Configs.Matrix>)>]
19+
type BFS<'elem when 'elem : struct>(
2020
buildFunToBenchmark,
2121
converter: string -> 'elem,
2222
binaryConverter,
@@ -98,7 +98,7 @@ type BFSBenchmarksWithoutDataTransfer<'elem when 'elem : struct>(
9898
boolConverter,
9999
vertex) =
100100

101-
inherit BFSBenchmarks<'elem>(
101+
inherit BFS<'elem>(
102102
buildFunToBenchmark,
103103
converter,
104104
boolConverter,
@@ -128,7 +128,7 @@ type BFSBenchmarksWithTransfer<'elem when 'elem : struct>(
128128
boolConverter,
129129
vertex) =
130130

131-
inherit BFSBenchmarks<'elem>(
131+
inherit BFS<'elem>(
132132
buildFunToBenchmark,
133133
converter,
134134
boolConverter,
@@ -163,7 +163,7 @@ type BFSIntWithoutTransferBenchmark() =
163163
0)
164164

165165
static member InputMatrixProvider =
166-
BFSBenchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
166+
BFS<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
167167

168168
type BFSIntWithTransferBenchmark() =
169169

@@ -174,5 +174,5 @@ type BFSIntWithTransferBenchmark() =
174174
0)
175175

176176
static member InputMatrixProvider =
177-
BFSBenchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
177+
BFS<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
178178

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace GraphBLAS.FSharp.Benchmarks.Columns
2+
3+
open BenchmarkDotNet.Columns
4+
open BenchmarkDotNet.Reports
5+
open BenchmarkDotNet.Running
6+
open GraphBLAS.FSharp.IO
7+
8+
type CommonColumn<'a>(benchmarkCaseConvert, columnName: string, getShape: 'a -> 'b) =
9+
interface IColumn with
10+
member this.AlwaysShow = true
11+
member this.Category = ColumnCategory.Params
12+
member this.ColumnName = columnName
13+
14+
member this.GetValue(_: Summary, benchmarkCase: BenchmarkCase) =
15+
benchmarkCaseConvert benchmarkCase
16+
|> getShape
17+
|> sprintf "%A"
18+
19+
member this.GetValue(summary: Summary, benchmarkCase: BenchmarkCase, _: SummaryStyle) =
20+
(this :> IColumn).GetValue(summary, benchmarkCase)
21+
22+
member this.Id = sprintf $"%s{columnName}"
23+
24+
member this.IsAvailable(_: Summary) = true
25+
member this.IsDefault(_: Summary, _: BenchmarkCase) = false
26+
member this.IsNumeric = true
27+
member this.Legend = sprintf $"%s{columnName}"
28+
member this.PriorityInCategory = 1
29+
member this.UnitType = UnitType.Size
30+
31+
type MatrixColumn(name, getShape) =
32+
inherit CommonColumn<MtxReader>(
33+
(fun benchmarkCase -> benchmarkCase.Parameters.["InputMatrixReader"] :?> MtxReader),
34+
name,
35+
getShape)
36+
37+
type Matrix2Column(name, getShape) =
38+
inherit CommonColumn<MtxReader*MtxReader>(
39+
(fun benchmarkCase -> benchmarkCase.Parameters.["InputMatrixReader"] :?> MtxReader * MtxReader),
40+
name,
41+
getShape)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
module GraphBLAS.FSharp.Benchmarks.Configs
2+
3+
open BenchmarkDotNet.Columns
4+
open BenchmarkDotNet.Toolchains.InProcess.Emit
5+
open GraphBLAS.FSharp.IO
6+
open BenchmarkDotNet.Configs
7+
open BenchmarkDotNet.Jobs
8+
open GraphBLAS.FSharp.Benchmarks.Columns
9+
10+
type Matrix2() =
11+
inherit ManualConfig()
12+
13+
do
14+
base.AddColumn(
15+
Matrix2Column("RowCount", (fun (matrix,_) -> matrix.ReadMatrixShape().RowCount)) :> IColumn,
16+
Matrix2Column("ColumnCount", (fun (matrix,_) -> matrix.ReadMatrixShape().ColumnCount)) :> IColumn,
17+
Matrix2Column(
18+
"NNZ",
19+
fun (matrix,_) ->
20+
match matrix.Format with
21+
| Coordinate -> matrix.ReadMatrixShape().Nnz
22+
| Array -> 0
23+
)
24+
:> IColumn,
25+
Matrix2Column(
26+
"SqrNNZ",
27+
fun (_,matrix) ->
28+
match matrix.Format with
29+
| Coordinate -> matrix.ReadMatrixShape().Nnz
30+
| Array -> 0
31+
)
32+
:> IColumn,
33+
StatisticColumn.Min,
34+
StatisticColumn.Max
35+
)
36+
|> ignore
37+
38+
type Matrix() =
39+
inherit ManualConfig()
40+
41+
do
42+
base.AddColumn(
43+
MatrixColumn("RowCount", (fun matrix -> matrix.ReadMatrixShape().RowCount)) :> IColumn,
44+
MatrixColumn("ColumnCount", (fun matrix -> matrix.ReadMatrixShape().ColumnCount)) :> IColumn,
45+
MatrixColumn(
46+
"NNZ",
47+
fun matrix ->
48+
match matrix.Format with
49+
| Coordinate -> matrix.ReadMatrixShape().Nnz
50+
| Array -> 0
51+
)
52+
:> IColumn,
53+
StatisticColumn.Min,
54+
StatisticColumn.Max
55+
)
56+
|> ignore
57+
58+
base.AddJob(
59+
Job
60+
.Dry
61+
.WithToolchain(InProcessEmitToolchain.Instance)
62+
.WithWarmupCount(3)
63+
.WithIterationCount(10)
64+
.WithInvocationCount(3)
65+
)
66+
|> ignore
67+
68+
type MinMaxMean() =
69+
inherit ManualConfig()
70+
71+
do
72+
base.AddColumn(
73+
StatisticColumn.Min,
74+
StatisticColumn.Max,
75+
StatisticColumn.Mean
76+
)
77+
|> ignore

benchmarks/GraphBLAS-sharp.Benchmarks/GraphBLAS-sharp.Benchmarks.fsproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
</ItemGroup>
1717
<ItemGroup>
1818
<Compile Include="AssemblyInfo.fs" />
19-
<Compile Include="MatrixExtensions.fs" />
2019
<Compile Include="Helpers.fs" />
21-
<Compile Include="BenchmarksBFS.fs" />
22-
<Compile Include="BenchmarksMxv.fs" />
23-
<Compile Include="BenchmarksEWiseAdd.fs" />
24-
<Compile Include="BenchmarksMxm.fs" />
20+
<Compile Include="Columns.fs" />
21+
<Compile Include="Configs.fs" />
2522
<!--Compile Include="BenchmarksTranspose.fs" /-->
26-
<Compile Include="BenchmarksMathNET.fs" />
27-
<Compile Include="VectorEWiseAddGen.fs" />
23+
<Compile Include="Matrix\SpGeMM\Masked.fs" />
24+
<Compile Include="Matrix\Map2\Map2.fs" />
25+
<Compile Include="Matrix\Map2\MathNET.fs" />
26+
<Compile Include="Vector\Map2.fs" />
27+
<Compile Include="Algorithms\BFS.fs" />
2828
<Compile Include="Program.fs" />
2929
</ItemGroup>
3030
<Import Project="..\..\.paket\Paket.Restore.targets" />

0 commit comments

Comments
 (0)