File tree Expand file tree Collapse file tree 1 file changed +39
-6
lines changed
Expand file tree Collapse file tree 1 file changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -17,12 +17,6 @@ The version of StringBuilder built on an array of strings string[]: uses less me
1717
1818``` C#
1919
20- [IterationSetup ]
21- public void Setup ()
22- {
23- _str = new string ('S' , StrLength );
24- }
25-
2620 [Benchmark (Baseline = true , Description = " StringBuilder" )]
2721 public void StringBuilder ()
2822 {
@@ -88,6 +82,45 @@ The version of StringBuilder built on an array of strings string[]: uses less me
8882| StringBuilderArray | 1071741 | 152,856.84 μs | 0.53 | - | - | - | 2093269.14 KB | 0.50 |
8983
9084## Reuse instance benchmark
85+ ``` C#
86+
87+ [Benchmark (Baseline = true , Description = " StringBuilder" )]
88+ public void StringBuilder ()
89+ {
90+ var sb = new System .Text .StringBuilder ();
91+ for (int i = 0 ; i < 1000 ; i ++ )
92+ {
93+ sb .AppendLine (_str );
94+ }
95+
96+ sb .Clear ();
97+ for (int i = 0 ; i < 1000 ; i ++ )
98+ {
99+ sb .AppendLine (_str );
100+ }
101+
102+ var result = sb .ToString ();
103+ }
104+
105+ [Benchmark (Description = " StringBuilderArray" )]
106+ public void StringBuilderArray ()
107+ {
108+ var sb = new StringBuilderArray .StringBuilderArray ();
109+ for (int i = 0 ; i < 1000 ; i ++ )
110+ {
111+ sb .AppendLine (_str );
112+ }
113+
114+ sb .Clear ();
115+ for (int i = 0 ; i < 1000 ; i ++ )
116+ {
117+ sb .AppendLine (_str );
118+ }
119+
120+ var result = sb .ToString ();
121+ }
122+
123+ ```
91124
92125| Method | StrLength | Mean | Ratio | Gen0 | Gen1 | Gen2 | Allocated | Alloc Ratio |
93126| ------------------- | ---------- | --------------:| ------:| ----------:| ----------:| ----------:| --------------:| ------------:|
You can’t perform that action at this time.
0 commit comments