Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/benchmarks/micro/MicroBenchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<Compile Remove="libraries\System.Text.Json\Serializer\WritePreservedReferences.cs" />
<Compile Remove="libraries\System.Net.Security\SslStreamTests.Context.cs" />
<Compile Remove="libraries\System.Formats.Cbor\*.cs" />
<Compile Remove="libraries\System.Runtime\Perf.Half.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' Or ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(_TargetFrameworkVersionWithoutV)' &lt; '6.0')">
Expand Down Expand Up @@ -217,5 +218,4 @@
<!-- Workaround https://github.com/dotnet/project-system/issues/935 -->
<None Include="**/*.cs" />
</ItemGroup>

</Project>
43 changes: 43 additions & 0 deletions src/benchmarks/micro/libraries/System.Runtime/Perf.Half.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using BenchmarkDotNet.Attributes;

Comment on lines +10 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: empty lines

Suggested change
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;

using MicroBenchmarks;

namespace System.Tests
{
[BenchmarkCategory(Categories.Libraries)]
public class Perf_Half
{
public static IEnumerable<Half> Values => new Half[]
{
BitConverter.UInt16BitsToHalf(0x03ff), //Maximum subnormal number in Half
(Half)12345.0f /* same value used by other tests to compare the perf */,
BitConverter.UInt16BitsToHalf(0x7dff) //NaN
};

public static IEnumerable<float> SingleValues => new float[]
{
6.097555E-05f,
12345.0f /* same value used by other tests to compare the perf */,
65520.0f, //Minimum value that is infinity in Half
Comment on lines +22 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: inconsistent comments

Suggested change
BitConverter.UInt16BitsToHalf(0x03ff), //Maximum subnormal number in Half
(Half)12345.0f /* same value used by other tests to compare the perf */,
BitConverter.UInt16BitsToHalf(0x7dff) //NaN
};
public static IEnumerable<float> SingleValues => new float[]
{
6.097555E-05f,
12345.0f /* same value used by other tests to compare the perf */,
65520.0f, //Minimum value that is infinity in Half
BitConverter.UInt16BitsToHalf(0x03ff), // Maximum subnormal number in Half
(Half)12345.0f, // same value used by other tests to compare the perf
BitConverter.UInt16BitsToHalf(0x7dff) // NaN
};
public static IEnumerable<float> SingleValues => new float[]
{
6.097555E-05f,
12345.0f, // same value used by other tests to compare the perf
65520.0f // Minimum value that is infinity in Half

float.NaN
};

[Benchmark]
[ArgumentsSource(nameof(SingleValues))]
public Half SingleToHalf(float value) => (Half)value;

[Benchmark]
[ArgumentsSource(nameof(Values))]
public float HalfToSingle(Half value) => (float)value;
}
}