-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance improvement for nested collections. Benchmarks for multip…
…le mappers. Release 0.9.5
- Loading branch information
1 parent
6d47867
commit ba13f08
Showing
20 changed files
with
889 additions
and
54 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
using Mapster; | ||
using PerformanceTest.Enums; | ||
using PerformanceTest.Models; | ||
using PerformanceTest.ViewModels; | ||
|
||
namespace PerformanceTest.Mapping | ||
{ | ||
public class MapsterMapperMappings | ||
{ | ||
public static void Init() | ||
{ | ||
TypeAdapterConfig<Product, ProductViewModel> | ||
.NewConfig() | ||
.Map(dest => dest.DefaultSharedOption, src => TypeAdapter.Adapt<ProductVariant, ProductVariantViewModel>(src.DefaultOption)); | ||
|
||
TypeAdapterConfig<Test, TestViewModel> | ||
.NewConfig() | ||
.Map(dest => dest.Age, src => src.Age) | ||
.Map(dest => dest.Weight, src => src.Weight * 2) | ||
.Map(dest => dest.Type, src => (Types)src.Type) | ||
.Map(dest => dest.Name, src => string.Format("{0} - {1} - {2}", src.Name, src.Weight, src.Age)) | ||
.Map(dest => dest.Name, src => string.Format("{0} - {1} - {2}", src.Name, src.Weight, src.Age)) | ||
.Map(dest => dest.SpareTheProduct, src => TypeAdapter.Adapt<Product, ProductViewModel>(src.SpareProduct)) | ||
.Map(dest => dest.Description, src => string.Format("{0} - {1}", src.Name, src.Id)); | ||
|
||
TypeAdapterConfig<User, UserViewModel> | ||
.NewConfig() | ||
.Map(dest => dest.BelongTo, src => TypeAdapter.Adapt<Role, RoleViewModel>(src.Role)); | ||
|
||
|
||
TypeAdapterConfig<Author, AuthorViewModel> | ||
.NewConfig() | ||
.Map(dest => dest.OwnedArticles, src => TypeAdapter.Adapt<IEnumerable<Article>, ArticleViewModel[]>(src.Articles)); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using OoMapper; | ||
using PerformanceTest.Enums; | ||
using PerformanceTest.Models; | ||
using PerformanceTest.Tests; | ||
using PerformanceTest.ViewModels; | ||
|
||
namespace PerformanceTest.Mapping | ||
{ | ||
public class OoMapperMappings | ||
{ | ||
public static void Init() | ||
{ | ||
Mapper.Reset(); | ||
Mapper.CreateMap<ProductVariant, ProductVariantViewModel>(); | ||
Mapper.CreateMap<Product, ProductViewModel>() | ||
.ForMember(dest => dest.DefaultSharedOption, src => src.MapFrom(m => m.DefaultOption)); | ||
Mapper.CreateMap<Test, TestViewModel>() | ||
.ForMember(dest => dest.Weight, opt => opt.MapFrom(src => src.Weight * 2)) | ||
.ForMember(dest => dest.Age, opt => opt.MapFrom(src => src.Age)) | ||
.ForMember(dest => dest.Type, src => src.MapFrom(m => (Types)m.Type)) | ||
.ForMember(dest => dest.Name, src => src.MapFrom(m => string.Format("{0} - {1} - {2}", m.Name, m.Weight, m.Age))) | ||
.ForMember(dest => dest.SpareTheProduct, opt => opt.MapFrom(src => src.SpareProduct)) | ||
.ForMember(dest => dest.Description, opt => opt.MapFrom(src => string.Format("{0} - {1}", src.Name, src.Id))) | ||
.ForMember(dest => dest.Products, opt => opt.MapFrom(src => src.Products)); | ||
|
||
Mapper.CreateMap<News, NewsViewModel>(); | ||
|
||
Mapper.CreateMap<Role, RoleViewModel>(); | ||
Mapper.CreateMap<User, UserViewModel>() | ||
.ForMember(dest => dest.BelongTo, src => src.MapFrom(m => m.Role)); | ||
|
||
Mapper.CreateMap<Article, ArticleViewModel>(); | ||
Mapper.CreateMap<Author, AuthorViewModel>() | ||
.ForMember(dest => dest.OwnedArticles, src => src.MapFrom(m => m.Articles)); | ||
|
||
Mapper.CreateMap<Item, ItemViewModel>(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Nelibur.ObjectMapper; | ||
using PerformanceTest.Models; | ||
using PerformanceTest.Tests; | ||
using PerformanceTest.ViewModels; | ||
|
||
namespace PerformanceTest.Mapping | ||
{ | ||
public class TinyMapperMappings | ||
{ | ||
public static void Init() | ||
{ | ||
TinyMapper.Bind<ProductVariant, ProductVariantViewModel>(); | ||
|
||
TinyMapper.Bind<News, NewsViewModel>(); | ||
|
||
TinyMapper.Bind<Item, ItemViewModel>(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Omu.ValueInjecter; | ||
using PerformanceTest.Enums; | ||
using PerformanceTest.Models; | ||
using PerformanceTest.ViewModels; | ||
|
||
namespace PerformanceTest.Mapping | ||
{ | ||
public class ValueInjectorMappings | ||
{ | ||
public static void Init() | ||
{ | ||
Mapper.Reset(); | ||
|
||
Mapper.AddMap<Product, ProductViewModel>(src => | ||
{ | ||
var productViewModel = new ProductViewModel(); | ||
productViewModel.InjectFrom(src); | ||
productViewModel.DefaultSharedOption = | ||
Mapper.Map<ProductVariant, ProductVariantViewModel>(src.DefaultOption); | ||
productViewModel.Options = new List<ProductVariantViewModel>(); | ||
foreach (var pv in src.Options) | ||
{ | ||
productViewModel.Options.Add(Mapper.Map<ProductVariant, ProductVariantViewModel>(pv)); | ||
} | ||
return productViewModel; | ||
}); | ||
|
||
Mapper.AddMap<Test, TestViewModel>(src => | ||
{ | ||
var testViewModel = new TestViewModel(string.Format("{0} - {1}", src.Name, src.Id)); | ||
testViewModel.InjectFrom(src); | ||
|
||
testViewModel.Name = string.Format("{0} - {1} - {2}", src.Name, src.Weight, src.Age); | ||
|
||
testViewModel.Product = Mapper.Map<Product, ProductViewModel>(src.Product); | ||
testViewModel.SpareTheProduct = Mapper.Map<Product, ProductViewModel>(src.SpareProduct); | ||
testViewModel.Type = (Types) src.Type; | ||
testViewModel.Weight = src.Weight*2; | ||
testViewModel.Products = new List<ProductViewModel>(); | ||
foreach (var product in src.Products) | ||
{ | ||
testViewModel.Products.Add(Mapper.Map<Product, ProductViewModel>(product)); | ||
} | ||
return testViewModel; | ||
}); | ||
|
||
Mapper.AddMap<User, UserViewModel>(src => | ||
{ | ||
var userViewModel = new UserViewModel(); | ||
userViewModel.InjectFrom(src); | ||
userViewModel.BelongTo = Mapper.Map<Role, RoleViewModel>(src.Role); | ||
return userViewModel; | ||
}); | ||
|
||
Mapper.AddMap<Author, AuthorViewModel>(src => | ||
{ | ||
var articles = new ArticleViewModel[src.Articles.Count()]; | ||
var authorViewModel = new AuthorViewModel(); | ||
authorViewModel.InjectFrom(src); | ||
|
||
for (var i = 0; i < articles.Length; i++) | ||
{ | ||
articles[i] = Mapper.Map<Article, ArticleViewModel>(src.Articles.ElementAt(i)); | ||
} | ||
authorViewModel.OwnedArticles = articles; | ||
return authorViewModel; | ||
}); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.