Last active
July 1, 2018 09:35
-
-
Save vasily-kirichenko/cf415009537c1040baaa26f639a8e6e7 to your computer and use it in GitHub Desktop.
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
[<MemoryDiagnoser>] | |
type Betch() = | |
let s = "123 456" | |
[<Benchmark(Baseline = true)>] | |
member __.Array() = | |
let [|foo; bar|] = s.Split ' ' | |
let _x = | |
match BigInteger.TryParse foo, Int32.TryParse bar with | |
| (true, x), (true, y) -> x, y | |
| _ -> failwith "oops" | |
() | |
[<Benchmark>] | |
member __.Span() = | |
let idx = s.IndexOf ' ' | |
let foo = s.AsSpan(0, idx) | |
let bar = s.AsSpan(idx + 1) | |
let _x = | |
match BigInteger.TryParse foo, Int32.TryParse bar with | |
| (true, x), (true, y) -> x, y | |
| _ -> failwith "oops" | |
() | |
[<EntryPoint>] | |
let main _ = | |
BenchmarkRunner.Run<Betch>() |> ignore | |
0 | |
BenchmarkDotNet=v0.10.14, OS=Windows 10.0.17134 | |
Intel Core i5-7600 CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 4 physical cores | |
.NET Core SDK=2.1.301 | |
[Host] : .NET Core 2.1.1 (CoreCLR 4.6.26606.02, CoreFX 4.6.26606.05), 64bit RyuJIT DEBUG | |
DefaultJob : .NET Core 2.1.1 (CoreCLR 4.6.26606.02, CoreFX 4.6.26606.05), 64bit RyuJIT | |
Method | Mean | Error | StdDev | Scaled | Gen 0 | Allocated | | |
------- |---------:|---------:|---------:|-------:|-------:|----------:| | |
Array | 418.1 ns | 3.346 ns | 3.130 ns | 1.00 | 0.0787 | 248 B | | |
Span | 346.7 ns | 4.160 ns | 3.891 ns | 0.83 | 0.0453 | 144 B | | |
BenchmarkDotNet=v0.10.14, OS=macOS High Sierra 10.13.5 (17F77) [Darwin 17.6.0] | |
Intel Core i5-7600 CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 4 physical cores | |
.NET Core SDK=2.1.301 | |
[Host] : .NET Core 2.1.1 (CoreCLR 4.6.26606.02, CoreFX 4.6.26606.05), 64bit RyuJIT DEBUG | |
DefaultJob : .NET Core 2.1.1 (CoreCLR 4.6.26606.02, CoreFX 4.6.26606.05), 64bit RyuJIT | |
Method | Mean | Error | StdDev | Scaled | ScaledSD | Gen 0 | Allocated | | |
------- |---------:|----------:|----------:|-------:|---------:|-------:|----------:| | |
Array | 511.0 ns | 9.020 ns | 8.437 ns | 1.00 | 0.00 | 0.0782 | 248 B | | |
Span | 426.5 ns | 11.596 ns | 14.240 ns | 0.83 | 0.03 | 0.0453 | 144 B | | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment