Created
November 12, 2024 21:48
-
-
Save vzarytovskii/cf31d28dad940299285b0a9b68fa4201 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.Attributes | |
open BenchmarkDotNet.Configs | |
open BenchmarkDotNet.Environments | |
open BenchmarkDotNet.Jobs | |
open BenchmarkDotNet.Running | |
[<MemoryDiagnoser(displayGenColumns=false)>] | |
[<HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")>] | |
type Benchmarks () = | |
let x = Some 3 | |
[<Benchmark>] | |
member _.DoSomeStuffWithOptions () = | |
x | |
|> Option.map ((+) 1) // Used to allocate on the heap, now it doesn't. | |
|> Option.map ((+) -1) // Used to allocate on the heap, now it doesn't. | |
|> Option.defaultValue 0 | |
ignore <| BenchmarkRunner.Run<Benchmarks> | |
(DefaultConfig.Instance | |
.AddJob(Job.Default.AsBaseline().WithRuntime CoreRuntime.Core80) | |
.AddJob(Job.Default.WithRuntime CoreRuntime.Core90)) |
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
| Method | Runtime | Mean | Ratio | Allocated | Alloc Ratio | | |
|----------------------- |--------- |----------:|------:|----------:|------------:| | |
| DoSomeStuffWithOptions | .NET 8.0 | 3.8792 ns | 1.00 | 48 B | 1.00 | | |
| DoSomeStuffWithOptions | .NET 9.0 | 0.6274 ns | 0.16 | - | 0.00 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, "side-effects" of inlining will oftentimes result in allocations being also inlined as opposed to being in their own functions. Like it happened to be the case for the
Option
module. We might wanna see how things are inlining in certain CEs or maybe Asyncs (I suspect it's not gonna be inlining too much).