Last active
September 23, 2016 09:28
-
-
Save manofstick/e090c61b8d03b3fbee701eabcaf1753d 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.Collections.Generic | |
open System.Collections | |
open System | |
type Item = { | |
Value : int | |
Data1 : float | |
Data2 : float | |
Data3 : float | |
Data4 : float | |
} | |
type ListFilter () = | |
let mutable _list = Unchecked.defaultof<_> | |
let doFilter f = | |
_list |> List.filter f |> ignore | |
[<Params(6, 66, 666, 6666)>] | |
member val public Length = 0 with get, set | |
[<Setup>] | |
member this.SetupData() = | |
_list <- List.init this.Length (fun n -> { Value = n+1; Data1 = 0.; Data2 = 0.; Data3 = 0.; Data4 = 0. }) | |
[<Benchmark>] member __.Half () = doFilter (fun n -> n.Value % 2 = 0) | |
[<Benchmark>] member __.Quarter () = doFilter (fun n -> n.Value % 4 = 0) | |
[<Benchmark>] member __.Eighth () = doFilter (fun n -> n.Value % 8 = 0) | |
[<Benchmark>] member __.Sixteenth () = doFilter (fun n -> n.Value % 16 = 0) | |
[<Benchmark>] member __.Half_Step_4 () = doFilter (fun n -> n.Value &&& 4 = 4) | |
[<Benchmark>] member __.Half_Step_16 () = doFilter (fun n -> n.Value &&& 16 = 16) | |
[<Benchmark>] member __.Half_Step_64 () = doFilter (fun n -> n.Value &&& 64 = 64) | |
[<Benchmark>] member __.All () = doFilter (fun _ -> true) | |
[<Benchmark>] member __.None () = doFilter (fun _ -> false) | |
[<Benchmark>] member this.FirstQuarter () = doFilter (fun n -> n.Value < this.Length / 4) | |
[<Benchmark>] member this.LastQuarter () = doFilter (fun n -> n.Value > this.Length * 3 / 4) | |
[<Benchmark>] member this.Single () = doFilter (fun n -> n.Value = this.Length / 2) | |
[<Benchmark>] member this.Few () = doFilter (fun n -> (n.Value = this.Length * 1 / 4) || (n.Value = this.Length * 2 / 4) || (n.Value = this.Length * 3 / 4)) | |
[<Benchmark>] member this.AllButFirst () = doFilter (fun n -> n.Value > 1) | |
[<Benchmark>] member this.AllButLast () = doFilter (fun n -> n.Value < this.Length) | |
let makeJob jit platform = | |
Job (Jit = jit, | |
Platform = platform, | |
LaunchCount = Count 2, | |
WarmupCount = Count 10, | |
TargetCount = Count 20, | |
IterationTime = Count 20) | |
let [<EntryPoint>] main args = | |
let config = ManualConfig.Create DefaultConfig.Instance | |
config.Add (MemoryDiagnoser ()) | |
config.Add (makeJob Jit.RyuJit Platform.X64) | |
config.Add (makeJob Jit.LegacyJit Platform.X86) | |
BenchmarkRunner.Run<ListFilter> config |> ignore | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment