forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (48 loc) · 2.3 KB
/
Program.cs
File metadata and controls
62 lines (48 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using NUnit.Framework;
using ServiceStack.Common.Tests;
using ServiceStack.Reflection;
namespace ServiceStack.Text.TestsConsole
{
class Program
{
static void Main(string[] args)
{
//var da = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("dyn"), AssemblyBuilderAccess.Save);
//var dm = da.DefineDynamicModule("dyn_mod", "dyn.dll");
//var dt = dm.DefineType("dyn_type");
//var type = typeof(KeyValuePair<string,string>);
//var pi = type.GetProperty("Key");
//var lambdaValueType = PropertyInvoker.GetExpressionLambda<KeyValuePair<string,string>>(pi);
//lambdaValueType.CompileToMethod(dt.DefineMethod("KVP", MethodAttributes.Public | MethodAttributes.Static));
//var lambdaRefType = PropertyInvoker.GetExpressionLambda<TRef>(typeof(TRef).GetProperty("PropRef"));
//lambdaRefType.CompileToMethod(dt.DefineMethod("TRef_PropRef", MethodAttributes.Public | MethodAttributes.Static));
//var lambdaRefType2 = PropertyInvoker.GetExpressionLambda<IncludeExclude>(typeof(IncludeExclude).GetProperty("Id"));
//lambdaRefType2.CompileToMethod(dt.DefineMethod("IncludeExclude_Id", MethodAttributes.Public | MethodAttributes.Static));
//dt.CreateType();
//da.Save("dyn.dll");
new StringConcatPerfTests {
MultipleIterations = new[] { 1000, 10000, 100000, 1000000, 10000000 }
}.Compare_interpolation_vs_string_Concat();
Console.ReadLine();
}
class StringConcatPerfTests : PerfTestBase
{
public void Compare_interpolation_vs_string_Concat()
{
CompareMultipleRuns(
"Interpolation",
() => SimpleInterpolation("foo"),
"string.Concat",
() => SimpleConcat("foo"));
}
}
public static object SimpleInterpolation(string text) => $"Hi {text}";
public static object SimpleFormat(string text) => string.Format("Hi {0}", text);
public static object SimpleConcat(string text) => "Hi " + text;
}
}