Skip to content

Commit

Permalink
perf: more testing with different benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper Bollen authored and Casper Bollen committed Oct 19, 2023
1 parent a5ccbf4 commit 137dcf8
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```
BenchmarkDotNet v0.13.9+228a464e8be6c580ad9408e98f18813f6407fb5a, macOS Sonoma 14.0 (23A344) [Darwin 23.0.0]
Apple M2 Max, 1 CPU, 12 logical and 12 physical cores
.NET SDK 6.0.415
[Host] : .NET 6.0.23 (6.0.2323.48002), Arm64 RyuJIT AdvSIMD DEBUG
DefaultJob : .NET 6.0.23 (6.0.2323.48002), Arm64 RyuJIT AdvSIMD
```
| Method | Mean | Error | StdDev |
|-------------------- |----------:|----------:|----------:|
| AllPairsBR_100 | 6.251 ms | 0.0584 ms | 0.0547 ms |
| AllPairsBR_200 | 39.407 ms | 0.6607 ms | 0.6181 ms |
| AllPairsBR_Rand_100 | 9.480 ms | 0.1136 ms | 0.1063 ms |
| AllPairsBR_Rand_200 | 50.965 ms | 0.1216 ms | 0.1078 ms |
163 changes: 107 additions & 56 deletions benchmark/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ module Utils =
)


let getTwoRandomLists n max =
let xs1 = randomBigRationals 1 n max
let xs2 = randomBigRationals 2 n max
xs1, xs2



open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
open MathNet.Numerics
Expand All @@ -136,7 +143,89 @@ open Informedica.GenUnits.Lib
open Informedica.GenSolver.Lib


type Benchmarks () =
type BigRationalBenchmarks () =

let allPairs_100 = Utils.allPairs 1N 1N 100N
let allPairs_200 = Utils.allPairs 1N 1N 200N


let rand_100_a, rand_100_b = Utils.getTwoRandomLists 100 1_000

let rand_200_a, rand_200_b = Utils.getTwoRandomLists 200 1_000

let calc op x1 x2 =
Array.allPairs x1 x2
|> Array.map (fun (x1, x2) -> x1 |> op <| x2)
|> Array.distinct

let add = calc (+)
let sub = calc (-)
let mul = calc (*)
let div = calc (/)

[<Benchmark>]
member this.AllPairsBR_100 () =
let x1, x2 = allPairs_100
add x1 x2 |> ignore
sub x1 x2 |> ignore
mul x1 x2 |> ignore
div x1 x2 |> ignore


[<Benchmark>]
member this.AllPairsBR_200 () =
let x1, x2 = allPairs_200

add x1 x2 |> ignore
sub x1 x2 |> ignore
mul x1 x2 |> ignore
div x1 x2 |> ignore


[<Benchmark>]
member this.AllPairsBR_Rand_100 () =
let x1, x2 = rand_100_a, rand_100_b

add x1 x2 |> ignore
sub x1 x2 |> ignore
mul x1 x2 |> ignore
div x1 x2 |> ignore


[<Benchmark>]
member this.AllPairsBR_Rand_200 () =
let x1, x2 = rand_200_a, rand_200_b

add x1 x2 |> ignore
sub x1 x2 |> ignore
mul x1 x2 |> ignore
div x1 x2 |> ignore



type ValueUnitBenchmarks () =


let allPairs_100 =
Utils.allPairs 1N 1N 100N
|> fun (x1, x2) -> ValueUnit.create Units.Count.times x1, ValueUnit.create Units.Count.times x2

let allPairs_200 =
Utils.allPairs 1N 1N 200N
|> fun (x1, x2) -> ValueUnit.create Units.Count.times x1, ValueUnit.create Units.Count.times x2

let rand_100_a, rand_100_b =
Utils.getTwoRandomLists 100 1_000
|> fun (x1, x2) -> ValueUnit.create Units.Count.times x1, ValueUnit.create Units.Count.times x2

let rand_200_a, rand_200_b =
Utils.getTwoRandomLists 200 1_000
|> fun (x1, x2) -> ValueUnit.create Units.Count.times x1, ValueUnit.create Units.Count.times x2




type EquationBenchmarks () =

let eqs_n n a b c d e f =
let eqs =
Expand Down Expand Up @@ -180,27 +269,15 @@ type Benchmarks () =
let allPairsInt_100 = Utils.allPairs 1 1 100
let allPairsInt_1_000 = Utils.allPairs 1 1 200

let allPairs_100 = Utils.allPairs 1N 1N 100N
let allPairs_200 = Utils.allPairs 1N 1N 200N

let getTwoRandomLists n max =
let xs1 = Utils.randomBigRationals 1 n max
let xs2 = Utils.randomBigRationals 2 n max
xs1, xs2

let eqs_1_Rand n =
let xs1, xs2 = getTwoRandomLists n 1_000
let xs1, xs2 = Utils.getTwoRandomLists n 1_000
eqs_n 1 None (Some xs1) (Some xs2) None None None

let eqs_3_Rand n =
let xs1, xs2 = getTwoRandomLists n 1_000
let xs1, xs2 = Utils.getTwoRandomLists n 1_000
eqs_n 3 None (Some xs1) (Some xs2) None None None


let rand_100_a, rand_100_b = getTwoRandomLists 100 1_000

let rand_200_a, rand_200_b = getTwoRandomLists 200 1_000

let eqs_1_rand_10 = eqs_1_Rand 10

let eqs_1_rand_20 = eqs_1_Rand 20
Expand Down Expand Up @@ -236,42 +313,6 @@ type Benchmarks () =
|> Array.distinct


[<Benchmark>]
member this.AllPairsBR_100 () =
let x1, x2 = allPairs_100

Array.allPairs x1 x2
|> Array.map (fun (x1, x2) -> x1 + x2)
|> Array.distinct


[<Benchmark>]
member this.AllPairsBR_200 () =
let x1, x2 = allPairs_200

Array.allPairs x1 x2
|> Array.map (fun (x1, x2) -> x1 + x2)
|> Array.distinct


[<Benchmark>]
member this.AllPairsBR_Rand_100 () =
let x1, x2 = rand_100_a, rand_100_b

Array.allPairs x1 x2
|> Array.map (fun (x1, x2) -> x1 + x2)
|> Array.distinct


[<Benchmark>]
member this.AllPairsBR_Rand_200 () =
let x1, x2 = rand_200_a, rand_200_b

Array.allPairs x1 x2
|> Array.map (fun (x1, x2) -> x1 + x2)
|> Array.distinct


[<Benchmark>]
member this.SolveCountMinIncl () =
solveCountMinIncl "a" 10N eqs_1
Expand Down Expand Up @@ -321,11 +362,21 @@ type Benchmarks () =
[<EntryPoint>]
let main (args: string[]) =

Benchmarks().Print()

printfn "Starting to run benchmarks"
let _ = BenchmarkRunner.Run<Benchmarks>()
printfn "Finished running benchmarks"
match args with
| [|s|] when s = "pr" -> EquationBenchmarks().Print()

| [|s|] when s = "br" ->
printfn "Starting to run benchmarks"
let _ = BenchmarkRunner.Run<BigRationalBenchmarks>()
printfn "Finished running benchmarks"

| [|s|] when s = "eq" ->
printfn "Starting to run benchmarks"
let _ = BenchmarkRunner.Run<EquationBenchmarks>()
printfn "Finished running benchmarks"
| _ ->
printfn $"""Unknown args: {String.Join(" ", args)}"""
()

0

Expand Down
2 changes: 1 addition & 1 deletion benchmark/run.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sudo dotnet run -c Release
sudo dotnet run -c Release %*

0 comments on commit 137dcf8

Please sign in to comment.