-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About my similar projects #4
Comments
I try to add benchmark code in this project
+ [MemoryDiagnoser]
[DisassemblyDiagnoser]
public class StoreLong
{
[Benchmark]
public long ValueAsPerf()
{
Value value = new(42L);
return value.As<long>();
}
[Benchmark(Baseline = true)]
public long ValueTryPerf()
{
Value value = new(42L);
value.TryGetValue(out long result);
return result;
}
[Benchmark]
public long ValueCastOutPerf()
{
Value value = new(42L);
return (long)value;
}
[Benchmark]
public long ValueCastInPerf()
{
Value value = 42L;
value.TryGetValue(out long result);
return result;
}
+ [Benchmark]
+ public long UnionValueAsPerf()
+ {
+ UnionValue value = default;
+ value.Long = 42L;
+ return value;
+ }
+ [Benchmark]
+ public long UnionCaseInPerf()
+ {
+ UnionValue value = 42L;
+ return value;
+ }
} BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19045
AMD Ryzen 7 5800H with Radeon Graphics, 1 CPU, 16 logical and 8 physical cores
.NET SDK=8.0.100
[Host] : .NET 6.0.25 (6.0.2523.51912), X64 RyuJIT
DefaultJob : .NET 6.0.25 (6.0.2523.51912), X64 RyuJIT
I think my weakness is that it was not created from a constructor, nor was it read-only |
But I try to benchmark modifiable and read-only struct, the result shocked me a lot. But as far as I know, read-only structures will be optimized by JIT, and the result should be that read-only structures are better than mutable ones. [MemoryDiagnoser]
public class NewAndSet
{
[Benchmark(Baseline =true)]
public ReadonlyNew FromReadonlyNew()
{
return new ReadonlyNew(42);
}
[Benchmark]
public Modifyable FromModifyable()
{
Modifyable n = default;
n.val = 42;
return n;
}
public readonly struct ReadonlyNew
{
public ReadonlyNew(int value)
{
Value = value;
}
public int Value { get; }
}
public struct Modifyable
{
public int val;
public int Value
{
get => val;
set => val = value;
}
}
} The result
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my project UnionType, I also try to use memory overlap to store all type(decimal,Guid,object also support by use GCHandle weak or pin)
For object store I use 8bytes store intptr 8bytes store type name intptr.
In benchmark decimal test, there was a good result.
But I don't know if this will help in a real project, I always try to expand coreclr internal class, always thinks why it will be set internal.
I'm 96% covered in unit tests, but object store design will be hard for any time. The GC of the class instance should be controlled, and no one wants memory leakage.
Thanks.
The text was updated successfully, but these errors were encountered: