Skip to content

Instantly share code, notes, and snippets.

open System.Diagnostics
open System.Reflection
open Microsoft.FSharp.Core
open Microsoft.FSharp.Core.Operators
open Microsoft.FSharp.Core.LanguagePrimitives
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
open Microsoft.FSharp.Collections
open Microsoft.FSharp.Primitives.Basics
open System.Collections.Generic
@liboz
liboz / Benchmark.fs
Created July 25, 2016 10:04
groupByBenchmarkDotNet
open BenchmarkDotNet.Running
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Diagnostics.Windows
type groupBy () =
[<Params(10, 100, 10000, 1000000, 10000000)>]
member val public count = 0 with get, set
[<Benchmark>]
member this.groupByModulus () =
open BenchmarkDotNet.Running
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Diagnostics.Windows
let pairwiseOriginal (list: 'T list) =
let array = List.toArray list
if array.Length < 2 then [] else
List.init (array.Length-1) (fun i -> array.[i],array.[i+1])
open BenchmarkDotNet.Running
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Diagnostics.Windows
let rec chooseAllAcc f xs acc =
match xs with
| [] -> List.rev acc
| h :: t ->
match f h with
open BenchmarkDotNet.Running
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Diagnostics.Windows
let scanOriginal<'T,'State> f (s:'State) (list:'T list) =
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let rec loop s xs acc =
match xs with
| [] -> List.rev acc
open System.Diagnostics
let run (f : 'a -> 'b) l =
let res = f l
for i in 2..200 do
f l |> ignore
res
let count = 1000000
let listOfInts = [1..count]
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
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
let mapFold (f:'a -> 'b -> 'c * 'a) (s:'a) (l:'b list) : 'c list * 'a =
// microbenchmark suggested this implementation is faster than the simpler recursive one, and this function is called a lot
let mutable s = s
let mutable r = []
for x in l do
let x',s' = f s x
s <- s'
r <- x' :: r
List.rev r, s