Last active
October 3, 2016 01:47
-
-
Save liboz/28b89317526a4f9750f46b83f012eafa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open BenchmarkDotNet.Running | |
open BenchmarkDotNet.Attributes | |
open BenchmarkDotNet.Configs | |
open BenchmarkDotNet.Diagnostics.Windows | |
open BenchmarkDotNet.Jobs | |
open System.Linq | |
type map () = | |
[<Params(10, 100, 10000)>] | |
member val public count = 0 with get, set | |
member val public testList = [] with get, set | |
member val public testArray = [||] with get, set | |
member val public testSeq = Unchecked.defaultof<seq<int>> with get, set | |
[<Setup>] | |
member this.SetupData() = | |
this.testList <- [1..this.count] | |
this.testArray <- [|1..this.count|] | |
this.testSeq <- seq { 1..this.count } | |
[<Benchmark>] | |
member this.interfaceListTest () = | |
Seq.map id this.testList | |
|> Seq.filter (fun i -> i % 2 = 0) | |
|> Seq.map id | |
|> Seq.skip 5 | |
|> Seq.toList | |
[<Benchmark>] | |
member this.normalListTest () = | |
Seq.mapTest id this.testList | |
|> Seq.filterTest (fun i -> i % 2 = 0) | |
|> Seq.mapTest id | |
|> Seq.skipTest 5 | |
|> Seq.toList | |
[<Benchmark>] | |
member this.linqList () = | |
this.testList.Select(id).Where(fun i -> i % 2 = 0).Select(id).Skip(5) | |
|> Seq.toList | |
[<Benchmark>] | |
member this.interfaceArrayTest () = | |
Seq.map id this.testArray | |
|> Seq.filter (fun i -> i % 2 = 0) | |
|> Seq.map id | |
|> Seq.skip 5 | |
|> Seq.toList | |
[<Benchmark>] | |
member this.normalArrayTest () = | |
Seq.mapTest id this.testArray | |
|> Seq.filterTest (fun i -> i % 2 = 0) | |
|> Seq.mapTest id | |
|> Seq.skipTest 5 | |
|> Seq.toList | |
[<Benchmark>] | |
member this.linqArray () = | |
this.testArray.Select(id).Where(fun i -> i % 2 = 0).Select(id).Skip(5) | |
|> Seq.toList | |
[<Benchmark>] | |
member this.interfaceSeqTest () = | |
Seq.map id this.testSeq | |
|> Seq.filter (fun i -> i % 2 = 0) | |
|> Seq.map id | |
|> Seq.skip 5 | |
|> Seq.toList | |
[<Benchmark>] | |
member this.normalSeqTest () = | |
Seq.mapTest id this.testSeq | |
|> Seq.filterTest (fun i -> i % 2 = 0) | |
|> Seq.mapTest id | |
|> Seq.skipTest 5 | |
|> Seq.toList | |
[<Benchmark>] | |
member this.linqSeq () = | |
this.testSeq.Select(id).Where(fun i -> i % 2 = 0).Select(id).Skip(5) | |
|> Seq.toList | |
let makeJob (jit: Jit) (platform: Platform) = | |
let job = new Job() | |
job.Jit <- jit | |
job.Platform <- platform | |
job.LaunchCount <- new Count(5) | |
job.TargetCount <- new Count(50) | |
job | |
let [<EntryPoint>] main args = | |
let config = ManualConfig.Create(DefaultConfig.Instance) | |
config.Add(new MemoryDiagnoser()) | |
config.Add(makeJob Jit.RyuJit Platform.X64) | |
config.Add(makeJob Jit.LegacyJit Platform.X86) | |
BenchmarkRunner.Run<map>(config) |> ignore | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment