4
4
// Author: Jeff Hansen <[email protected] >
5
5
// Copyright (C) Jeff Hansen 2015. All rights reserved.
6
6
7
- using System ;
8
- using System . Collections . Generic ;
9
- using System . Text ;
10
-
11
7
using Jeffijoe . MessageFormat . Formatting ;
12
- using Jeffijoe . MessageFormat . Helpers ;
13
8
using Jeffijoe . MessageFormat . Tests . TestHelpers ;
14
-
15
9
using Xunit ;
16
- using Xunit . Abstractions ;
17
10
18
11
namespace Jeffijoe . MessageFormat . Tests
19
12
{
20
13
/// <summary>
21
14
/// The message formatter_caching_tests.
22
15
/// </summary>
23
- public class MessageFormatterCachingTests
16
+ public class MessageFormatterCachingTests ( )
24
17
{
25
- #region Fields
26
-
27
- /// <summary>
28
- /// The output helper.
29
- /// </summary>
30
- private readonly ITestOutputHelper outputHelper ;
31
-
32
- #endregion
33
-
34
- #region Constructors and Destructors
35
-
36
- /// <summary>
37
- /// Initializes a new instance of the <see cref="MessageFormatterCachingTests"/> class.
38
- /// </summary>
39
- /// <param name="outputHelper">
40
- /// The output helper.
41
- /// </param>
42
- public MessageFormatterCachingTests ( ITestOutputHelper outputHelper )
43
- {
44
- this . outputHelper = outputHelper ;
45
- }
46
-
47
- #endregion
48
-
49
18
#region Public Methods and Operators
50
19
51
20
/// <summary>
@@ -75,71 +44,7 @@ public void FormatMessage_caches_reused_pattern()
75
44
Assert . Equal ( "Hi Ma'am!" , actual ) ;
76
45
Assert . Equal ( 3 , parser . ParseCount ) ;
77
46
}
78
-
79
- /// <summary>
80
- /// The format message_with_cache_benchmark.
81
- /// </summary>
82
- [ Fact ]
83
- public void FormatMessage_with_cache_benchmark ( )
84
- {
85
- var subject = new MessageFormatter ( useCache : true ) ;
86
- this . Benchmark ( subject ) ;
87
- }
88
-
89
- /// <summary>
90
- /// The format message_without_cache_benchmark.
91
- /// </summary>
92
- [ Fact ]
93
- public void FormatMessage_without_cache_benchmark ( )
94
- {
95
- var subject = new MessageFormatter ( false ) ;
96
- this . Benchmark ( subject ) ;
97
- }
98
-
99
- #endregion
100
-
101
- #region Methods
102
-
103
- /// <summary>
104
- /// The benchmark.
105
- /// </summary>
106
- /// <param name="subject">
107
- /// The subject.
108
- /// </param>
109
- private void Benchmark ( MessageFormatter subject )
110
- {
111
- var pattern = "\r \n ----\r \n Oh {name}? And if we were " + "to surround {gender, select, " + "male {his} "
112
- + "female {her}" + "} name with '{' and '}', it would look "
113
- + "like '{'{name}'}'? Yeah, I know {gender, select, " + "male {him} " + "female {her}"
114
- + "}. {gender, select, " + "male {He's}" + "female {She's}" + "} got {messageCount, plural, "
115
- + "zero {no messages}" + "one {just one message}" + "=42 {a universal amount of messages}"
116
- + "other {uuhm... let's see.. Oh yeah, # messages - and here's a pound: '#'}" + "}!" ;
117
- int iterations = 100000 ;
118
- var args = new Dictionary < string , object ? > [ iterations ] ;
119
- var rnd = new Random ( ) ;
120
- for ( int i = 0 ; i < iterations ; i ++ )
121
- {
122
- var val = rnd . Next ( 50 ) ;
123
- args [ i ] =
124
- new
125
- {
126
- gender = val % 2 == 0 ? "male" : "female" ,
127
- name = val % 2 == 0 ? "Jeff" : "Marcela" ,
128
- messageCount = val
129
- } . ToDictionary ( ) ;
130
- }
131
-
132
- TestHelpers . Benchmark . Start ( "Formatting message " + iterations + " times, no warm-up." , this . outputHelper ) ;
133
- var output = new StringBuilder ( ) ;
134
- for ( int i = 0 ; i < iterations ; i ++ )
135
- {
136
- output . AppendLine ( subject . FormatMessage ( pattern , args [ i ] ) ) ;
137
- }
138
-
139
- TestHelpers . Benchmark . End ( this . outputHelper ) ;
140
- this . outputHelper . WriteLine ( output . ToString ( ) ) ;
141
- }
142
-
47
+
143
48
#endregion
144
49
}
145
50
}
0 commit comments