Created
September 26, 2021 10:50
-
-
Save eramax/ac17c07797ce4c28bdedeed63cdd6c9f to your computer and use it in GitHub Desktop.
Mapster mapper
This file contains hidden or 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
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
using Mapster; | |
using System; | |
/// <summary> | |
/// Mapster, the best .NET mapper that you are (probably) not using | |
/// https://www.youtube.com/watch?v=UIslFVEHkzA | |
/// </summary> | |
public class Program | |
{ | |
public record User(string Username, string Password, string Email, string Fullname, int Department); | |
public record UserLogin(string Username, string Password, DateTime Date); | |
[MemoryDiagnoser, Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy:FastestToSlowest)] | |
public class Mapper | |
{ | |
private readonly User user; | |
public Mapper() => user = new User("eramax", "123456", "[email protected]", "Ahmed Morsi", 100); | |
[Benchmark] | |
public void MapsterMapper() | |
{ | |
var dto = user.Adapt<UserLogin>(); | |
//Console.WriteLine($"User to User login => {dto}"); | |
} | |
[Benchmark] | |
public void ManualMapping() | |
{ | |
var dto = new UserLogin(user.Username, user.Password, DateTime.Now); | |
//Console.WriteLine($"User to User login => {dto}"); | |
} | |
} | |
public static void Main(string[] args) | |
{ | |
var summary = BenchmarkRunner.Run<Program.Mapper>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment