dotnet / dotnet/fsharp

Investigate what it would mean to do benchmarks with Benchmark.NET in F# scripts

Open
#9,519 3 comments 5 reactions 0 assignees View on GitHub
Area-FSI Feature Request
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

NuGet references let us pull in packages for scripts. Yay!

One such package is Benchmark.NET. It's a great library. However, it's not as straightforward as say, Json.NET. Given the following script:

```fsharp
#r "nuget:BenchmarkDotNet"

open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running

module Op =
let inline not' x = if x then false else true
let inline not'' x = match x with true -> false | false -> true

[]
type NotBench() =
let s = "hello"

[]
member _.Not() =
let mutable b = false
for i=0 to 1 do b <- not (isNull s)
b

[]
member _.NotWithIf() =
let mutable b = false
for i=0 to 1 do b <- Op.not' (isNull s)
b

[]
member _.NotWithMatch() =
let mutable b = false
for i=0 to 1 do b <- Op.not'' (isNull s)
b

let summary = BenchmarkRunner.Run()
printfn "%A" summary
```

You get this result when run via `dotnet fsi`:

image

This is clearly thrown from Benchmark.NET, not F# Interactive. Is there something we could do to make this better? It's worth investigating IMO. Scripts are nicer for these kinds of things than console apps.

This may also have ramifications for doing similar things in notebooks.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.