diff --git a/src/benchmarks/micro-fsharp/Equality/Arrays.fs b/src/benchmarks/micro-fsharp/Equality/Arrays.fs new file mode 100644 index 00000000000..9803e198384 --- /dev/null +++ b/src/benchmarks/micro-fsharp/Equality/Arrays.fs @@ -0,0 +1,26 @@ +module MicroBenchmarks.FSharp.Equality.Arrays + +open BenchmarkDotNet.Attributes +open MicroBenchmarks.FSharp + +[] +[] +type Arrays() = + + let numbers = Array.init 1000 id + + [] + member _.Int32() = + numbers |> Array.countBy (fun n -> [| n % 7 |]) + + [] + member _.Int64() = + numbers |> Array.countBy (fun n -> [| int64 (n % 7) |]) + + [] + member _.Byte() = + numbers |> Array.countBy (fun n -> [| byte (n % 7) |]) + + [] + member _.Obj() = + numbers |> Array.countBy (fun n -> [| box (n % 7) |]) diff --git a/src/benchmarks/micro-fsharp/Equality/BasicTypes.fs b/src/benchmarks/micro-fsharp/Equality/BasicTypes.fs new file mode 100644 index 00000000000..99333de3048 --- /dev/null +++ b/src/benchmarks/micro-fsharp/Equality/BasicTypes.fs @@ -0,0 +1,65 @@ +module MicroBenchmarks.FSharp.Equality.BasicTypes + +open BenchmarkDotNet.Attributes +open MicroBenchmarks.FSharp + +[] +[] +type BasicTypes() = + + let bools = Array.init 1000 (fun n -> n % 2 = 0) + let sbytes = Array.init 1000 sbyte + let bytes = Array.init 1000 byte + let int16s = Array.init 1000 int16 + let uint16s = Array.init 1000 uint16 + let int32s = Array.init 1000 id + let uint32s = Array.init 1000 uint32 + let int64s = Array.init 1000 int64 + let uint64s = Array.init 1000 uint64 + let intptrs = Array.init 1000 nativeint + let uintptrs = Array.init 1000 unativeint + let chars = Array.init 1000 char + let strings = Array.init 1000 string + let decimals = Array.init 1000 decimal + + [] + member _.Bool() = bools |> Array.distinct + + [] + member _.SByte() = sbytes |> Array.distinct + + [] + member _.Byte() = bytes |> Array.distinct + + [] + member _.Int16() = int16s |> Array.distinct + + [] + member _.UInt16() = uint16s |> Array.distinct + + [] + member _.Int32() = int32s |> Array.distinct + + [] + member _.UInt32() = uint32s |> Array.distinct + + [] + member _.Int64() = int64s |> Array.distinct + + [] + member _.UInt64() = uint64s |> Array.distinct + + [] + member _.IntPtr() = intptrs |> Array.distinct + + [] + member _.UIntPtr() = uintptrs |> Array.distinct + + [] + member _.Char() = chars |> Array.distinct + + [] + member _.String() = strings |> Array.distinct + + [] + member _.Decimal() = decimals |> Array.distinct diff --git a/src/benchmarks/micro-fsharp/Equality/FSharpCoreFunctions.fs b/src/benchmarks/micro-fsharp/Equality/FSharpCoreFunctions.fs new file mode 100644 index 00000000000..76d756a9340 --- /dev/null +++ b/src/benchmarks/micro-fsharp/Equality/FSharpCoreFunctions.fs @@ -0,0 +1,105 @@ +module MicroBenchmarks.FSharp.Equality.FSharpCoreFunctions + +open BenchmarkDotNet.Attributes +open MicroBenchmarks.FSharp + +[] +type SomeStruct = + val A : int + new a = { A = a } + +[] +[] +type FSharpCoreFunctions() = + + let array = Array.init 1000 id + let list = List.init 1000 id + let seq = Seq.init 1000 id + + [] + member _.ArrayCountBy() = + array + |> Array.countBy (fun n -> SomeStruct(n % 7)) + + [] + member _.ArrayGroupBy() = + array + |> Array.groupBy (fun n -> SomeStruct(n % 7)) + + [] + member _.ArrayDistinct() = + array + |> Array.map (fun n -> SomeStruct(n % 7)) + |> Array.distinct + + [] + member _.ArrayDistinctBy() = + array + |> Array.distinctBy (fun n -> SomeStruct(n % 7)) + + [] + member _.ArrayExcept() = + array + |> Array.map SomeStruct + |> Array.except ([| SomeStruct 42 |]) + + [] + member _.ListCountBy() = + list + |> List.countBy (fun n -> SomeStruct(n % 7)) + + [] + member _.ListGroupBy() = + list + |> List.groupBy (fun n -> SomeStruct(n % 7)) + + [] + member _.ListDistinct() = + list + |> List.map (fun n -> SomeStruct(n % 7)) + |> List.distinct + + [] + member _.ListDistinctBy() = + list + |> List.distinctBy (fun n -> SomeStruct(n % 7)) + + [] + member _.ListExcept() = + List.init 1000 id + |> List.map SomeStruct + |> List.except ([| SomeStruct 42 |]) + + [] + member _.SeqCountBy() = + seq + |> Seq.countBy (fun n -> SomeStruct(n % 7)) + |> Seq.last + + [] + member _.SeqGroupBy() = + seq + |> Seq.groupBy (fun n -> SomeStruct(n % 7)) + |> Seq.last + + [] + member _.SeqDistinct() = + seq + |> Seq.map (fun n -> SomeStruct(n % 7)) + |> Seq.distinct + |> Seq.last + + [] + member _.SeqDistinctBy() = + seq + |> Seq.distinctBy (fun n -> SomeStruct(n % 7)) + |> Seq.last + + [] + member _.SeqExcept() = + seq + |> Seq.map SomeStruct + |> Seq.except ([| SomeStruct 42 |]) + |> Seq.last + + diff --git a/src/benchmarks/micro-fsharp/MicrobenchmarksFSharp.fsproj b/src/benchmarks/micro-fsharp/MicrobenchmarksFSharp.fsproj index 71aeac837d3..57b2fbed3b1 100644 --- a/src/benchmarks/micro-fsharp/MicrobenchmarksFSharp.fsproj +++ b/src/benchmarks/micro-fsharp/MicrobenchmarksFSharp.fsproj @@ -9,6 +9,9 @@ + + +