9
9
10
10
11
11
using System ;
12
+ using System . Collections ;
12
13
using System . Collections . Generic ;
13
14
using System . IO ;
14
15
using System . Runtime . Serialization . Formatters . Binary ;
@@ -19,37 +20,41 @@ namespace NHibernate.Test.UtilityTest
19
20
{
20
21
using System . Threading . Tasks ;
21
22
[ TestFixture ]
22
- public class LinkedHashMapFixtureAsync
23
+ public class LinkHashMapFixtureAsync
23
24
{
24
- private static readonly Player [ ] players = {
25
- new Player ( "12341" , "Boeta Dippenaar" ) , new Player ( "23432" , "Gary Kirsten" ) ,
26
- new Player ( "23411" , "Graeme Smith" ) , new Player ( "55221" , "Jonty Rhodes" ) ,
27
- new Player ( "61234" , "Monde Zondeki" ) , new Player ( "23415" , "Paul Adams" )
28
- } ;
25
+ private static readonly Player [ ] players =
26
+ {
27
+ new Player ( "12341" , "Boeta Dippenaar" ) ,
28
+ new Player ( "23432" , "Gary Kirsten" ) ,
29
+ new Player ( "23411" , "Graeme Smith" ) ,
30
+ new Player ( "55221" , "Jonty Rhodes" ) ,
31
+ new Player ( "61234" , "Monde Zondeki" ) ,
32
+ new Player ( "23415" , "Paul Adams" )
33
+ } ;
29
34
30
35
private static void Fill ( IDictionary < string , Player > lhm )
31
36
{
32
- foreach ( Player player in players )
37
+ foreach ( var player in players )
33
38
lhm . Add ( player . Id , player ) ;
34
39
}
35
40
36
41
[ Test , Explicit ]
37
42
public async Task ShowDiffAsync ( )
38
43
{
39
44
IDictionary < string , Player > dict = new Dictionary < string , Player > ( ) ;
40
- IDictionary < string , Player > lhm = new LinkedHashMap < string , Player > ( ) ;
45
+ IDictionary < string , Player > lhm = new LinkHashMap < string , Player > ( ) ;
41
46
Fill ( dict ) ;
42
47
Fill ( lhm ) ;
43
48
// Override the first element
44
- Player o = new Player ( "12341" , "Ovirride " ) ;
49
+ var o = new Player ( "12341" , "Override " ) ;
45
50
dict [ o . Id ] = o ;
46
51
lhm [ o . Id ] = o ;
47
52
await ( Console . Out . WriteLineAsync ( "Dictionary order:" ) ) ;
48
53
foreach ( KeyValuePair < string , Player > pair in dict )
49
54
{
50
55
Console . Out . WriteLine ( "Key->{0}" , pair . Key ) ;
51
56
}
52
- await ( Console . Out . WriteLineAsync ( "LinkedHashMap order:" ) ) ;
57
+ await ( Console . Out . WriteLineAsync ( "LinkHashMap order:" ) ) ;
53
58
foreach ( KeyValuePair < string , Player > pair in lhm )
54
59
{
55
60
Console . Out . WriteLine ( "Key->{0}" , pair . Key ) ;
@@ -65,18 +70,18 @@ public async Task PerformanceAsync()
65
70
66
71
int numOfEntries = Int16 . MaxValue ;
67
72
68
- long [ ] dictPopulateTicks = new long [ numOfRuns ] ;
69
- long [ ] dictItemTicks = new long [ numOfRuns ] ;
73
+ var dictPopulateTicks = new long [ numOfRuns ] ;
74
+ var dictItemTicks = new long [ numOfRuns ] ;
70
75
71
- long [ ] linkPopulateTicks = new long [ numOfRuns ] ;
72
- long [ ] linkItemTicks = new long [ numOfRuns ] ;
76
+ var linkPopulateTicks = new long [ numOfRuns ] ;
77
+ var linkItemTicks = new long [ numOfRuns ] ;
73
78
74
- for ( int runIndex = 0 ; runIndex < numOfRuns ; runIndex ++ )
79
+ for ( var runIndex = 0 ; runIndex < numOfRuns ; runIndex ++ )
75
80
{
76
81
string key ;
77
82
object value ;
78
83
IDictionary < string , object > dictionary = new Dictionary < string , object > ( ) ;
79
- IDictionary < string , object > linked = new LinkedHashMap < string , object > ( ) ;
84
+ IDictionary < string , object > linked = new LinkHashMap < string , object > ( ) ;
80
85
81
86
long dictStart = DateTime . Now . Ticks ;
82
87
@@ -118,12 +123,12 @@ public async Task PerformanceAsync()
118
123
linked . Clear ( ) ;
119
124
}
120
125
121
- for ( int runIndex = 0 ; runIndex < numOfRuns ; runIndex ++ )
126
+ for ( var runIndex = 0 ; runIndex < numOfRuns ; runIndex ++ )
122
127
{
123
128
decimal linkPopulateOverhead = ( linkPopulateTicks [ runIndex ] / ( decimal ) dictPopulateTicks [ runIndex ] ) ;
124
129
decimal linkItemOverhead = ( linkItemTicks [ runIndex ] / ( decimal ) dictItemTicks [ runIndex ] ) ;
125
130
126
- string message = string . Format ( "LinkedHashMap vs Dictionary (Run-{0}) :" , runIndex + 1 ) ;
131
+ string message = string . Format ( "LinkHashMap vs Dictionary (Run-{0}) :" , runIndex + 1 ) ;
127
132
message += "\n POPULATE:" ;
128
133
message += "\n \t linked took " + linkPopulateTicks [ runIndex ] + " ticks." ;
129
134
message += "\n \t dictionary took " + dictPopulateTicks [ runIndex ] + " ticks." ;
0 commit comments