Skip to content

Commit

Permalink
Added pointers to SampleBenchmark test.
Browse files Browse the repository at this point in the history
Added comment about `Type.IsClass` returns true for pointers.
  • Loading branch information
timcassell committed May 17, 2023
1 parent 7abb119 commit 48c10d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/BenchmarkDotNet/Engines/Consumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public void Consume<T>(in T value)
=> byteHolder = Unsafe.As<T, byte>(ref Unsafe.AsRef(in value));

internal static bool IsConsumable(Type type)
// IsClass returns true for pointers.
=> SupportedTypes.Contains(type) || type.GetTypeInfo().IsClass || type.GetTypeInfo().IsInterface || !type.IsByRefLike();

internal static bool HasConsumableField(Type type, out FieldInfo consumableField)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ public EmptyStruct ReturnManyArgsCase(ref double i, int j, string k, object l)
return ref refValueHolder;
}

[Benchmark]
public unsafe int* ReturnsIntPointer()
{
Thread.Sleep(100);
return default;
}

[Benchmark]
public unsafe void* ReturnsVoidPointer()
{
Thread.Sleep(100);
return default;
}

[Benchmark]
public unsafe EmptyStruct* ReturnsStructPointer()
{
Thread.Sleep(100);
return default;
}

[Benchmark, Arguments(12)]
public Task<int> TaskSample(long arg)
{
Expand Down

0 comments on commit 48c10d0

Please sign in to comment.