|
3 | 3 | using EntityGraphQL; |
4 | 4 | using EntityGraphQL.Compiler.Util; |
5 | 5 |
|
6 | | -namespace Benchmarks |
| 6 | +namespace Benchmarks; |
| 7 | + |
| 8 | +/// <summary> |
| 9 | +/// Was testing the performance of using reflection to build the correct types from variables or using System.Text.Json |
| 10 | +/// |
| 11 | +/// Reflection wins |
| 12 | +/// | Method | Job | Toolchain | IterationCount | LaunchCount | WarmupCount | Mean | Error | StdDev | |
| 13 | +/// |---------------------------- |----------- |----------------------- |--------------- |------------ |------------ |------------:|-------------:|-----------:| |
| 14 | +/// | ObjectWithJsonSerialization | Job-DOGPPG | InProcessEmitToolchain | Default | Default | Default | 7,524.18 ms | 146.326 ms | 227.812 ms | |
| 15 | +/// | ObjectWithReflection | Job-DOGPPG | InProcessEmitToolchain | Default | Default | Default | 21.77 ms | 0.355 ms | 0.332 ms | |
| 16 | +/// | ListWithJsonSerialization | Job-DOGPPG | InProcessEmitToolchain | Default | Default | Default | 9,686.72 ms | 193.058 ms | 327.827 ms | |
| 17 | +/// | ListWithReflection | Job-DOGPPG | InProcessEmitToolchain | Default | Default | Default | 44.22 ms | 0.202 ms | 0.189 ms | |
| 18 | +/// | ObjectWithJsonSerialization | ShortRun | Default | 3 | 1 | 3 | 7,278.49 ms | 5,676.616 ms | 311.154 ms | |
| 19 | +/// | ObjectWithReflection | ShortRun | Default | 3 | 1 | 3 | 20.41 ms | 1.685 ms | 0.092 ms | |
| 20 | +/// | ListWithJsonSerialization | ShortRun | Default | 3 | 1 | 3 | 9,877.59 ms | 2,168.229 ms | 118.848 ms | |
| 21 | +/// | ListWithReflection | ShortRun | Default | 3 | 1 | 3 | 43.14 ms | 36.734 ms | 2.013 ms | |
| 22 | +/// </summary> |
| 23 | +[ShortRunJob] |
| 24 | +public class ArgumentsBenchmarks |
7 | 25 | { |
8 | | - /// <summary> |
9 | | - /// Was testing the performance of using reflection to build the correct types from variables or using System.Text.Json |
10 | | - /// |
11 | | - /// Reflection wins |
12 | | - /// | Method | Job | Toolchain | IterationCount | LaunchCount | WarmupCount | Mean | Error | StdDev | |
13 | | - /// |---------------------------- |----------- |----------------------- |--------------- |------------ |------------ |------------:|-------------:|-----------:| |
14 | | - /// | ObjectWithJsonSerialization | Job-DOGPPG | InProcessEmitToolchain | Default | Default | Default | 7,524.18 ms | 146.326 ms | 227.812 ms | |
15 | | - /// | ObjectWithReflection | Job-DOGPPG | InProcessEmitToolchain | Default | Default | Default | 21.77 ms | 0.355 ms | 0.332 ms | |
16 | | - /// | ListWithJsonSerialization | Job-DOGPPG | InProcessEmitToolchain | Default | Default | Default | 9,686.72 ms | 193.058 ms | 327.827 ms | |
17 | | - /// | ListWithReflection | Job-DOGPPG | InProcessEmitToolchain | Default | Default | Default | 44.22 ms | 0.202 ms | 0.189 ms | |
18 | | - /// | ObjectWithJsonSerialization | ShortRun | Default | 3 | 1 | 3 | 7,278.49 ms | 5,676.616 ms | 311.154 ms | |
19 | | - /// | ObjectWithReflection | ShortRun | Default | 3 | 1 | 3 | 20.41 ms | 1.685 ms | 0.092 ms | |
20 | | - /// | ListWithJsonSerialization | ShortRun | Default | 3 | 1 | 3 | 9,877.59 ms | 2,168.229 ms | 118.848 ms | |
21 | | - /// | ListWithReflection | ShortRun | Default | 3 | 1 | 3 | 43.14 ms | 36.734 ms | 2.013 ms | |
22 | | - /// </summary> |
23 | | - [ShortRunJob] |
24 | | - public class ArgumentsBenchmarks |
25 | | - { |
26 | | - // [Benchmark] |
27 | | - // public void ObjectWithJsonSerialization() |
28 | | - // { |
29 | | - // var variables = new QueryVariables { |
30 | | - // { "names", new { Name = "Lisa", LastName = "Simpson" } } |
31 | | - // }; |
| 26 | + // [Benchmark] |
| 27 | + // public void ObjectWithJsonSerialization() |
| 28 | + // { |
| 29 | + // var variables = new QueryVariables { |
| 30 | + // { "names", new { Name = "Lisa", LastName = "Simpson" } } |
| 31 | + // }; |
32 | 32 |
|
33 | | - // for (int i = 0; i < 10000; i++) |
34 | | - // { |
35 | | - // var val = ExpressionUtil.ChangeType(variables["names"], typeof(InputType), true); |
36 | | - // } |
37 | | - // } |
38 | | - // [Benchmark] |
39 | | - // public void ListWithJsonSerialization() |
40 | | - // { |
41 | | - // var variables = new QueryVariables { |
42 | | - // { "names", new List<InputType2>{new InputType2{ Name = "Lisa", LastName = "Simpson" } }} |
43 | | - // }; |
| 33 | + // for (int i = 0; i < 10000; i++) |
| 34 | + // { |
| 35 | + // var val = ExpressionUtil.ChangeType(variables["names"], typeof(InputType), true); |
| 36 | + // } |
| 37 | + // } |
| 38 | + // [Benchmark] |
| 39 | + // public void ListWithJsonSerialization() |
| 40 | + // { |
| 41 | + // var variables = new QueryVariables { |
| 42 | + // { "names", new List<InputType2>{new InputType2{ Name = "Lisa", LastName = "Simpson" } }} |
| 43 | + // }; |
44 | 44 |
|
45 | | - // for (int i = 0; i < 10000; i++) |
46 | | - // { |
47 | | - // var val = ExpressionUtil.ChangeType(variables["names"], typeof(List<InputType>), true); |
48 | | - // } |
49 | | - // } |
| 45 | + // for (int i = 0; i < 10000; i++) |
| 46 | + // { |
| 47 | + // var val = ExpressionUtil.ChangeType(variables["names"], typeof(List<InputType>), true); |
| 48 | + // } |
| 49 | + // } |
50 | 50 |
|
51 | | - [Benchmark] |
52 | | - public static void ObjectWithReflection() |
53 | | - { |
54 | | - var variables = new QueryVariables { { "names", new { Name = "Lisa", LastName = "Simpson" } } }; |
| 51 | + [Benchmark] |
| 52 | + public static void ObjectWithReflection() |
| 53 | + { |
| 54 | + var variables = new QueryVariables { { "names", new { Name = "Lisa", LastName = "Simpson" } } }; |
55 | 55 |
|
56 | | - for (int i = 0; i < 10000; i++) |
57 | | - { |
58 | | - ExpressionUtil.ConvertObjectType(variables["names"], typeof(InputType), null, null); |
59 | | - } |
| 56 | + for (int i = 0; i < 10000; i++) |
| 57 | + { |
| 58 | + ExpressionUtil.ConvertObjectType(variables["names"], typeof(InputType), null, null); |
60 | 59 | } |
| 60 | + } |
61 | 61 |
|
62 | | - [Benchmark] |
63 | | - public static void ListWithReflection() |
| 62 | + [Benchmark] |
| 63 | + public static void ListWithReflection() |
| 64 | + { |
| 65 | + var variables = new QueryVariables |
64 | 66 | { |
65 | | - var variables = new QueryVariables |
66 | 67 | { |
| 68 | + "names", |
| 69 | + new List<InputType2> |
67 | 70 | { |
68 | | - "names", |
69 | | - new List<InputType2> |
70 | | - { |
71 | | - new InputType2 { Name = "Lisa", LastName = "Simpson" } |
72 | | - } |
| 71 | + new InputType2 { Name = "Lisa", LastName = "Simpson" }, |
73 | 72 | } |
74 | | - }; |
| 73 | + }, |
| 74 | + }; |
75 | 75 |
|
76 | | - for (int i = 0; i < 10000; i++) |
77 | | - { |
78 | | - ExpressionUtil.ConvertObjectType(variables["names"], typeof(List<InputType>), null, null); |
79 | | - } |
| 76 | + for (int i = 0; i < 10000; i++) |
| 77 | + { |
| 78 | + ExpressionUtil.ConvertObjectType(variables["names"], typeof(List<InputType>), null, null); |
80 | 79 | } |
81 | 80 | } |
| 81 | +} |
82 | 82 |
|
83 | | - // this would be the anonymous class created in compiling the query |
84 | | - internal class InputType |
85 | | - { |
86 | | - public string name = string.Empty; |
87 | | - public string lastName = string.Empty; |
88 | | - } |
| 83 | +// this would be the anonymous class created in compiling the query |
| 84 | +internal class InputType |
| 85 | +{ |
| 86 | + public string name = string.Empty; |
| 87 | + public string lastName = string.Empty; |
| 88 | +} |
89 | 89 |
|
90 | | - // This would be the class they pass in that matches the schema but is different from the anonymous class |
91 | | - internal class InputType2 |
92 | | - { |
93 | | - public string Name = string.Empty; |
94 | | - public string LastName = string.Empty; |
95 | | - } |
| 90 | +// This would be the class they pass in that matches the schema but is different from the anonymous class |
| 91 | +internal class InputType2 |
| 92 | +{ |
| 93 | + public string Name = string.Empty; |
| 94 | + public string LastName = string.Empty; |
96 | 95 | } |
0 commit comments