Skip to content

Commit

Permalink
perf: added more random benchmark tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper Bollen authored and Casper Bollen committed Oct 15, 2023
1 parent 8a68c43 commit 75595b8
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ Intel Core i7-6700K CPU 4.00GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
```
| Method | Mean | Error | StdDev |
|------------------ |-------------:|------------:|------------:|
| AllPairesInt_100 | 194.5 μs | 1.31 μs | 1.09 μs |
| AllPairsInt_200 | 1,313.1 μs | 18.35 μs | 16.26 μs |
| AllPairsBR_100 | 972.8 μs | 3.32 μs | 2.77 μs |
| AllPairsBR_200 | 5,275.6 μs | 18.56 μs | 15.50 μs |
| SolveCountMinIncl | 278.4 μs | 0.95 μs | 0.84 μs |
| Solve_1_Eqs_100 | 43,351.1 μs | 825.59 μs | 772.26 μs |
| Solve_1_Eqs_200 | 178,478.8 μs | 3,545.83 μs | 3,941.18 μs |
| Solve_3_Eqs_100 | 45,053.0 μs | 891.40 μs | 990.79 μs |
| Solve_3_Eqs_200 | 178,513.1 μs | 3,469.46 μs | 3,245.34 μs |
| Method | Mean | Error | StdDev |
|-------------------- |-------------:|------------:|------------:|
| AllPairesInt_100 | 200.5 μs | 2.35 μs | 1.96 μs |
| AllPairsInt_200 | 1,351.2 μs | 13.08 μs | 10.92 μs |
| AllPairsBR_100 | 994.5 μs | 4.76 μs | 4.22 μs |
| AllPairsBR_200 | 5,406.7 μs | 22.60 μs | 18.87 μs |
| AllPairsBR_Rand_100 | 3,571.2 μs | 15.51 μs | 13.75 μs |
| AllPairsBR_Rand_200 | 16,147.1 μs | 158.76 μs | 140.73 μs |
| SolveCountMinIncl | 281.5 μs | 1.07 μs | 0.89 μs |
| Solve_1_Eqs_100 | 44,174.2 μs | 870.02 μs | 854.48 μs |
| Solve_1_Eqs_200 | 177,626.8 μs | 3,524.22 μs | 4,582.48 μs |
| Solve_3_Eqs_100 | 45,644.5 μs | 724.51 μs | 642.26 μs |
| Solve_3_Eqs_200 | 179,394.1 μs | 3,491.76 μs | 4,779.56 μs |
| Solve_1_Eqs_Rand_10 | 24,787.3 μs | 93.87 μs | 78.39 μs |
| Solve_1_Eqs_Rand_20 | 271,758.6 μs | 3,096.51 μs | 2,896.48 μs |
| Solve_3_Eqs_Rand_10 | 25,649.5 μs | 89.37 μs | 69.78 μs |
| Solve_3_Eqs_Rand_20 | 269,382.4 μs | 1,385.37 μs | 1,295.88 μs |
99 changes: 89 additions & 10 deletions benchmark/Program.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// For more information see https://aka.ms/fsharp-console-apps

open System


module TestSolver =

Expand Down Expand Up @@ -99,6 +101,7 @@ module TestSolver =

module Utils =

open MathNet.Numerics

let inline allPairs min incr max =
let x1 = [|min..incr..max|]
Expand All @@ -107,12 +110,31 @@ module Utils =
x1, x2


let randomNums seed n max =
let rnd = Random(seed)

Array.init n (fun _ -> rnd.Next(1, max))


let randomBigRationals seed n max =
let nums = randomNums seed n max
let denums = randomNums (seed + 1) n max
Array.zip nums denums
|> Array.map (fun (n, d) ->
let n = BigRational.FromInt(n)
let d = BigRational.FromInt(d)
n / d
)


open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
open MathNet.Numerics

open TestSolver
open Informedica.GenUnits.Lib
open Informedica.GenSolver.Lib


type Benchmarks () =

Expand Down Expand Up @@ -161,6 +183,40 @@ type Benchmarks () =
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
eqs_n 1 None (Some xs1) (Some xs2) None None None

let eqs_3_Rand n =
let xs1, xs2 = 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

let eqs_3_rand_10 = eqs_3_Rand 10

let eqs_3_rand_20 = eqs_3_Rand 20


member this.Print () =
eqs_1_rand_10
|> List.map (Equation.toString true)
|> String.concat "\n"
|> printfn "%s"



[<Benchmark>]
member this.AllPairesInt_100 () =
Expand All @@ -180,36 +236,36 @@ type Benchmarks () =
|> Array.distinct


//[<Benchmark>]
member this.AllPairesInt_Commutative_100 () =
let x1, x2 = allPairsInt_100
[<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.AllPairsInt_Commutative_200 () =
let x1, x2 = allPairsInt_1_000
[<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_100 () =
let x1, x2 = allPairs_100
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_200 () =
let x1, x2 = allPairs_200
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)
Expand Down Expand Up @@ -240,11 +296,34 @@ type Benchmarks () =
solveAll eqs_3_max_200


[<Benchmark>]
member this.Solve_1_Eqs_Rand_10 () =
solveAll eqs_1_rand_10


[<Benchmark>]
member this.Solve_1_Eqs_Rand_20 () =
solveAll eqs_1_rand_20


[<Benchmark>]
member this.Solve_3_Eqs_Rand_10 () =
solveAll eqs_3_rand_10


[<Benchmark>]
member this.Solve_3_Eqs_Rand_20 () =
solveAll eqs_3_rand_20



// For more information see https://aka.ms/fsharp-console-apps
[<EntryPoint>]
let main (args: string[]) =

Benchmarks().Print()

printfn "Starting to run benchmarks"
let _ = BenchmarkRunner.Run<Benchmarks>()
printfn "Finished running benchmarks"

Expand Down

0 comments on commit 75595b8

Please sign in to comment.