-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* More F# microbenchmarks * Update MicrobenchmarksFSharp.fsproj
- Loading branch information
Showing
4 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module MicroBenchmarks.FSharp.Equality.Arrays | ||
|
||
open BenchmarkDotNet.Attributes | ||
open MicroBenchmarks.FSharp | ||
|
||
[<MemoryDiagnoser>] | ||
[<BenchmarkCategory(Categories.FSharpMicroCategory)>] | ||
type Arrays() = | ||
|
||
let numbers = Array.init 1000 id | ||
|
||
[<Benchmark>] | ||
member _.Int32() = | ||
numbers |> Array.countBy (fun n -> [| n % 7 |]) | ||
|
||
[<Benchmark>] | ||
member _.Int64() = | ||
numbers |> Array.countBy (fun n -> [| int64 (n % 7) |]) | ||
|
||
[<Benchmark>] | ||
member _.Byte() = | ||
numbers |> Array.countBy (fun n -> [| byte (n % 7) |]) | ||
|
||
[<Benchmark>] | ||
member _.Obj() = | ||
numbers |> Array.countBy (fun n -> [| box (n % 7) |]) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module MicroBenchmarks.FSharp.Equality.BasicTypes | ||
|
||
open BenchmarkDotNet.Attributes | ||
open MicroBenchmarks.FSharp | ||
|
||
[<MemoryDiagnoser>] | ||
[<BenchmarkCategory(Categories.FSharpMicroCategory)>] | ||
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 | ||
|
||
[<Benchmark>] | ||
member _.Bool() = bools |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.SByte() = sbytes |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.Byte() = bytes |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.Int16() = int16s |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.UInt16() = uint16s |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.Int32() = int32s |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.UInt32() = uint32s |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.Int64() = int64s |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.UInt64() = uint64s |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.IntPtr() = intptrs |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.UIntPtr() = uintptrs |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.Char() = chars |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.String() = strings |> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.Decimal() = decimals |> Array.distinct |
105 changes: 105 additions & 0 deletions
105
src/benchmarks/micro-fsharp/Equality/FSharpCoreFunctions.fs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
module MicroBenchmarks.FSharp.Equality.FSharpCoreFunctions | ||
|
||
open BenchmarkDotNet.Attributes | ||
open MicroBenchmarks.FSharp | ||
|
||
[<Struct>] | ||
type SomeStruct = | ||
val A : int | ||
new a = { A = a } | ||
|
||
[<MemoryDiagnoser>] | ||
[<BenchmarkCategory(Categories.FSharpMicroCategory)>] | ||
type FSharpCoreFunctions() = | ||
|
||
let array = Array.init 1000 id | ||
let list = List.init 1000 id | ||
let seq = Seq.init 1000 id | ||
|
||
[<Benchmark>] | ||
member _.ArrayCountBy() = | ||
array | ||
|> Array.countBy (fun n -> SomeStruct(n % 7)) | ||
|
||
[<Benchmark>] | ||
member _.ArrayGroupBy() = | ||
array | ||
|> Array.groupBy (fun n -> SomeStruct(n % 7)) | ||
|
||
[<Benchmark>] | ||
member _.ArrayDistinct() = | ||
array | ||
|> Array.map (fun n -> SomeStruct(n % 7)) | ||
|> Array.distinct | ||
|
||
[<Benchmark>] | ||
member _.ArrayDistinctBy() = | ||
array | ||
|> Array.distinctBy (fun n -> SomeStruct(n % 7)) | ||
|
||
[<Benchmark>] | ||
member _.ArrayExcept() = | ||
array | ||
|> Array.map SomeStruct | ||
|> Array.except ([| SomeStruct 42 |]) | ||
|
||
[<Benchmark>] | ||
member _.ListCountBy() = | ||
list | ||
|> List.countBy (fun n -> SomeStruct(n % 7)) | ||
|
||
[<Benchmark>] | ||
member _.ListGroupBy() = | ||
list | ||
|> List.groupBy (fun n -> SomeStruct(n % 7)) | ||
|
||
[<Benchmark>] | ||
member _.ListDistinct() = | ||
list | ||
|> List.map (fun n -> SomeStruct(n % 7)) | ||
|> List.distinct | ||
|
||
[<Benchmark>] | ||
member _.ListDistinctBy() = | ||
list | ||
|> List.distinctBy (fun n -> SomeStruct(n % 7)) | ||
|
||
[<Benchmark>] | ||
member _.ListExcept() = | ||
List.init 1000 id | ||
|> List.map SomeStruct | ||
|> List.except ([| SomeStruct 42 |]) | ||
|
||
[<Benchmark>] | ||
member _.SeqCountBy() = | ||
seq | ||
|> Seq.countBy (fun n -> SomeStruct(n % 7)) | ||
|> Seq.last | ||
|
||
[<Benchmark>] | ||
member _.SeqGroupBy() = | ||
seq | ||
|> Seq.groupBy (fun n -> SomeStruct(n % 7)) | ||
|> Seq.last | ||
|
||
[<Benchmark>] | ||
member _.SeqDistinct() = | ||
seq | ||
|> Seq.map (fun n -> SomeStruct(n % 7)) | ||
|> Seq.distinct | ||
|> Seq.last | ||
|
||
[<Benchmark>] | ||
member _.SeqDistinctBy() = | ||
seq | ||
|> Seq.distinctBy (fun n -> SomeStruct(n % 7)) | ||
|> Seq.last | ||
|
||
[<Benchmark>] | ||
member _.SeqExcept() = | ||
seq | ||
|> Seq.map SomeStruct | ||
|> Seq.except ([| SomeStruct 42 |]) | ||
|> Seq.last | ||
|
||
|
This file contains 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