This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MappingProfile : Profile | |
{ | |
public MappingProfile() | |
{ | |
CreateMap<Entity, Model>(); | |
} | |
} | |
public class MappingBenchmarks | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static unsafe void TypeSafety() | |
{ | |
int a = 1; | |
var ptr = Unsafe.AsPointer(ref a); | |
Unsafe.Write(ptr, 0); | |
var b = Unsafe.Read<bool>(ptr); | |
Console.WriteLine(b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.method public hidebysig static !!T Read<T>(void* source) cil managed aggressiveinlining | |
{ | |
.custom instance void System.Runtime.Versioning.NonVersionableAttribute::.ctor() = ( 01 00 00 00 ) | |
.maxstack 1 | |
ldarg.0 | |
ldobj !!T | |
ret | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static unsafe byte[] WriteVectorBuffer(ref Vector3 vec) | |
{ | |
Span<byte> buffer = stackalloc byte[sizeof(Vector3)]; | |
fixed (byte* b = buffer) | |
Unsafe.Write(b, vec); | |
return buffer.ToArray(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static unsafe byte[] GetVectorBytes(ref Vector3 vec) | |
{ | |
Span<byte> buffer = stackalloc byte[sizeof(Vector3)]; | |
fixed (byte* b = buffer) | |
Marshal.StructureToPtr(vec, new IntPtr(b), false); | |
return buffer.ToArray(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static unsafe byte[] GetVectorBytes(Vector3 vec) | |
{ | |
var buffer = new byte[sizeof(Vector3)]; | |
fixed (byte* b = buffer) | |
{ | |
Marshal.StructureToPtr(vec, new IntPtr(b), false); | |
return buffer; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
var vec = new Vector3 {X = 10, Y = 20, Z = 30}; | |
Foo(ref vec); | |
} | |
public static unsafe void Foo(ref Vector3 vec) | |
{ | |
fixed (Vector3* ptr = &vec) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HELP request_duration_seconds The duration in seconds between the response to a request. | |
# TYPE request_duration_seconds histogram | |
request_duration_seconds_sum{status_code="200",method="GET"} 0.0385083 | |
request_duration_seconds_count{status_code="200",method="GET"} 13 | |
request_duration_seconds_bucket{status_code="200",method="GET",le="0.01"} 12 | |
request_duration_seconds_bucket{status_code="200",method="GET",le="0.02"} 12 | |
request_duration_seconds_bucket{status_code="200",method="GET",le="0.04"} 13 | |
request_duration_seconds_bucket{status_code="200",method="GET",le="0.08"} 13 | |
request_duration_seconds_bucket{status_code="200",method="GET",le="0.16"} 13 | |
request_duration_seconds_bucket{status_code="200",method="GET",le="0.32"} 13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddSingleton<MetricReporter>(); | |
services.AddControllers(); | |
} | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
// Other middleware components omitted for brevity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ResponseMetricMiddleware | |
{ | |
private readonly RequestDelegate _request; | |
public ResponseMetricMiddleware(RequestDelegate request) | |
{ | |
_request = request ?? throw new ArgumentNullException(nameof(request)); | |
} | |
public async Task Invoke(HttpContext httpContext, MetricReporter reporter) |