-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathFormatBenchmarks.cs
More file actions
53 lines (46 loc) · 1.46 KB
/
FormatBenchmarks.cs
File metadata and controls
53 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Net;
using BenchmarkDotNet.Attributes;
namespace StackExchange.Redis.Benchmarks
{
[Config(typeof(CustomConfig))]
public class FormatBenchmarks
{
[GlobalSetup]
public void Setup() { }
[Benchmark]
[Arguments("64")]
[Arguments("-1")]
[Arguments("0")]
[Arguments("123442")]
public long ParseInt64(string s) => Format.ParseInt64(s);
[Benchmark]
[Arguments("64")]
[Arguments("-1")]
[Arguments("0")]
[Arguments("123442")]
public long ParseInt32(string s) => Format.ParseInt32(s);
[Benchmark]
[Arguments("64")]
[Arguments("-1")]
[Arguments("0")]
[Arguments("123442")]
[Arguments("-inf")]
[Arguments("nan")]
public double ParseDouble(string s) => Format.TryParseDouble(s, out var val) ? val : double.NaN;
private byte[] buffer = new byte[128];
[Benchmark]
[Arguments(64D)]
[Arguments(-1D)]
[Arguments(0D)]
[Arguments(123442D)]
[Arguments(double.NegativeInfinity)]
[Arguments(double.NaN)]
public int FormatDouble(double value) => Format.FormatDouble(value, buffer.AsSpan());
[Benchmark]
[Arguments("host.com", -1)]
[Arguments("host.com", 0)]
[Arguments("host.com", 65345)]
public EndPoint ParseEndPoint(string host, int port) => Format.ParseEndPoint(host, port);
}
}