Skip to content

Instantly share code, notes, and snippets.

@enricosada
Last active September 2, 2016 14:06
Show Gist options
  • Save enricosada/22b62181e4a322f9af738d80fc605a8f to your computer and use it in GitHub Desktop.
Save enricosada/22b62181e4a322f9af738d80fc605a8f to your computer and use it in GitHub Desktop.
BenchmarkDotNet.Artifacts/
bin/
obj/
.vscode/
project.lock.json
namespace benchfs
open System
open System.Security.Cryptography
open BenchmarkDotNet.Attributes
[<MyConfigAttribute>]
type Md5VsSha256Class () =
let sha256 = SHA256.Create()
let md5 = MD5.Create()
let mutable data : byte array = [| |]
[<Params(10)>]
member val N = 0 with get, set
[<Setup>]
member this.setup () =
data <- Array.zeroCreate this.N
(Random(42)).NextBytes(data)
[<Benchmark>]
member this.Sha256 () =
sha256.ComputeHash(data)
[<Benchmark>]
member this.Md5 () =
md5.ComputeHash(data)
[<MyConfig>]
module benchfs.Md5VsSha256Module
open System
open System.Security.Cryptography
open BenchmarkDotNet.Attributes
let sha256 = SHA256.Create()
let md5 = MD5.Create()
let mutable data = [| |]
[<Params(10)>]
let mutable N = 0
[<Setup>]
let setup () =
data <- Array.zeroCreate N
(Random(42)).NextBytes(data)
[<Benchmark>]
let sha256Algo () =
sha256.ComputeHash(data)
[<Benchmark>]
let md5Algo () =
md5.ComputeHash(data)
namespace benchfs
open System
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Jobs
type MyConfigAttribute () =
inherit Attribute()
let config =
[| Runtime.Core; Runtime.Clr |]
|> Array.map (fun runtime -> Job.Dry.With(runtime))
|> fun jobs -> ManualConfig.CreateEmpty().With(jobs)
interface IConfigSource with
member this.Config = config
module Program
open System
open System.Reflection
[<EntryPoint>]
let main argv =
let assembly = typeof<benchfs.MyConfigAttribute>.GetTypeInfo().Assembly
(*
let types : Type =
assembly.GetTypes()
|> Seq.filter (fun t -> t.GetTypeInfo().GetCustomAttributes(typeof<benchfs.MyConfigAttribute>, false) |> Seq.isEmpty |> not)
|> Seq.head
printfn "%A" types
let summary = BenchmarkDotNet.Running.BenchmarkRunner.Run(types)
*)
//let summary = BenchmarkDotNet.Running.BenchmarkRunner.Run<Md5VsSha256Class>()
let summary = (BenchmarkDotNet.Running.BenchmarkSwitcher(assembly)).Run(argv)
0
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"compilerName": "fsc",
"compile": {
"includeFiles": [
"MyConfig.fs",
"BenchAsModule.fs",
"BenchAsClass.fs",
"Program.fs"
]
}
},
"dependencies": {
"FSharp.Core": "4.0.1.7-alpha",
"BenchmarkDotNet": "0.9.9"
},
"frameworks": {
"net46": {},
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
},
"tools": {
"dotnet-compile-fsc": {
"version": "1.0.0-preview2-*",
"imports": "dnxcore50"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment