Skip to content

Commit

Permalink
recurse 1 vs recurse 10
Browse files Browse the repository at this point in the history
  • Loading branch information
Happypig375 committed Mar 4, 2019
1 parent 7f9e2aa commit a0eac56
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
14 changes: 7 additions & 7 deletions MathDisplay.Tests.Benchmarks/Program.fs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Program =
let [<EntryPoint>] main _ =
printfn "Benchmark started."
printfn "Press Enter to run..."
System.Console.ReadLine() |> ignore
//printfn "Benchmark started."
//printfn "Press Enter to run..."
//System.Console.ReadLine() |> ignore
BenchmarkDotNet.Running.BenchmarkRunner.Run<MathDisplay.Tests.Benchmarks.
Result_ExceptionBenchmark
>() |> ignore
printfn ""
printfn "Benchmark ended."
printfn "Press any key to continue..."
System.Console.ReadLine() |> ignore
//printfn ""
//printfn "Benchmark ended."
//printfn "Press any key to continue..."
//System.Console.ReadLine() |> ignore
0
17 changes: 13 additions & 4 deletions MathDisplay.Tests.Benchmarks/Result_ExceptionBenchmark.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,40 @@ type Result_ExceptionBenchmark() =
let rec recurse = function
| 10 -> Ok 1
| n -> match recurse (n+1) with Ok i -> Ok (i + 1) | Error e -> Error e
recurse 10 |> ignore
recurse 1 |> ignore
[<Benchmark>]
member __.Ok_Exception() =
let rec recurse = function
| 10 -> 1
| n -> match recurse (n+1) with i -> i + 1
try recurse 10 |> ignore with _ -> ()
try recurse 1 |> ignore with _ -> ()
[<Benchmark>]
member __.Error_Result() =
let rec recurse = function
| 10 -> Error "asd"
| n -> match recurse (n+1) with Ok i -> Ok (i + 1) | Error e -> Error e
recurse 10 |> ignore
recurse 1 |> ignore
[<Benchmark>]
member __.Error_Exception() =
let rec recurse = function
| 10 -> failwith "asd"
| n -> match recurse (n+1) with i -> i + 1
try recurse 10 |> ignore with _ -> ()
try recurse 1 |> ignore with _ -> ()

(*
//recurse 10
Method | Mean | Error | StdDev |
---------------- |--------------:|------------:|------------:|
Ok_Result | 4.412 ns | 0.0259 ns | 0.0229 ns |
Ok_Exception | 2.275 ns | 0.0328 ns | 0.0307 ns |
Error_Result | 3.758 ns | 0.0234 ns | 0.0219 ns |
Error_Exception | 28,647.859 ns | 118.3354 ns | 110.6910 ns |
//recurse 1
Method | Mean | Error | StdDev |
---------------- |-------------:|------------:|------------:|
Ok_Result | 46.72 ns | 0.2317 ns | 0.2167 ns |
Ok_Exception | 17.36 ns | 0.1735 ns | 0.1623 ns |
Error_Result | 37.50 ns | 0.1186 ns | 0.1110 ns |
Error_Exception | 39,582.16 ns | 204.3940 ns | 181.1899 ns |
*)

0 comments on commit a0eac56

Please sign in to comment.