Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BenchmarkDotNet already supports running F# benchmarks on .NET Core #135

Closed
adamsitnik opened this issue Apr 2, 2016 · 3 comments
Closed

Comments

@adamsitnik
Copy link
Member

This week at #Build2016 F# support for .NET Core was announced. I have grabbed our code to check what is needed to be done to get it working. It turns out that we already support it!! Mainly due to the reuse of dotnet cli features.

So I just added sample F# benchmark to our repo, it can be found here I have reused existing F# sample.

project.json:

{
  "version": "1.0.0-*",

  "compilationOptions": {
    "emitEntryPoint": true,
    "optimize": true
  },

  "compilerName": "fsc",
  "compileFiles": [
    "Program.fs"
  ],

  "commands": {
    "run": "BenchmarkDotNet.Samples.FSharp"
  },

  "dependencies": {
    "BenchmarkDotNet": {
      "target": "package",
      "version": "0.9.4-beta"
    },
    "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-151221",
    "NETStandard.Library": "1.0.0-rc2-23811"
  },

  "frameworks": {
    "dnxcore50": { }
  }
}

Program.fs

module Program

open System
open System.IO
open System.Collections.Concurrent
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running

let getStrings len = Array.init len (fun _ -> Path.GetRandomFileName())

let lookup arr (dict:ConcurrentDictionary<string,bool>) =
    arr |> Array.iteri(fun idx elm -> 
        let mutable b = dict.[elm]
        b <- dict.[arr.[0]])


type StringKeyComparison () =
    let mutable arr : string [] = [||]
    let dict1 = ConcurrentDictionary<_,_>()
    let dict2 = ConcurrentDictionary<_,_>(StringComparer.Ordinal)

    [<Params (100, 500, 1000, 2000)>] 
    member val public DictSize = 0 with get, set

    [<Setup>]
    member self.SetupData() =
        dict1.Clear(); dict2.Clear()
        arr <- getStrings self.DictSize
        arr |> Array.iter (fun x -> dict1.[x] <- true ; dict2.[x] <- true)

    [<Benchmark>]
    member self.StandardLookup () = lookup arr dict1

    [<Benchmark>]
    member self.OrdinalLookup () = lookup arr dict2


let defaultSwitch () = BenchmarkSwitcher [| typeof<StringKeyComparison>  |]

[<EntryPoint>]
let Main args =
    defaultSwitch().Run args 
    0

NuGet.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
    <add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="fsharp-daily" value="https://www.myget.org/F/fsharp-daily/api/v3/index.json" />
  </packageSources>
</configuration>

commands needed to execute:

dotnet restore
dotnet run

@AndreyAkinshin
Copy link
Member

@adamsitnik, great news! Can you add a line to README about F# (Summary section)?

@adamsitnik
Copy link
Member Author

@AndreyAkinshin Before I added line to README I had also checked the Visual Basic support. It works as well so I added integration test for that and the line in README too. Commmit

@AndreyAkinshin
Copy link
Member

Cool! Thanks for checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants