-
Notifications
You must be signed in to change notification settings - Fork 279
/
Copy pathPerf.Int128.cs
55 lines (44 loc) · 1.85 KB
/
Perf.Int128.cs
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
54
55
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using MicroBenchmarks;
namespace System.Tests
{
[BenchmarkCategory(Categories.Libraries)]
public class Perf_Int128
{
private char[] _destination = new char[Int128.MinValue.ToString().Length];
public static IEnumerable<object> StringValues => Values.Select(value => value.ToString()).ToArray();
public static IEnumerable<object> Values => new object[]
{
Int128.MinValue,
(Int128)12345, // same value used by other tests to compare the perf
Int128.MaxValue,
};
[Benchmark]
[ArgumentsSource(nameof(Values))]
[MemoryRandomization]
public string ToString(Int128 value) => value.ToString();
[Benchmark]
[ArgumentsSource(nameof(StringValues))]
public Int128 Parse(string value) => Int128.Parse(value);
[Benchmark]
[ArgumentsSource(nameof(StringValues))]
public bool TryParse(string value) => Int128.TryParse(value, out _);
[Benchmark]
[ArgumentsSource(nameof(Values))]
public bool TryFormat(Int128 value) => value.TryFormat(new Span<char>(_destination), out _);
[Benchmark]
[ArgumentsSource(nameof(StringValues))]
public Int128 ParseSpan(string value) => Int128.Parse(value.AsSpan());
[Benchmark]
[ArgumentsSource(nameof(StringValues))]
public bool TryParseSpan(string value) => Int128.TryParse(value.AsSpan(), out _);
[Benchmark]
[Arguments(1, -1)]
public Int128 CopySign(Int128 value, Int128 sign) => Int128.CopySign(value, sign);
}
}