Skip to content

Commit c3b74df

Browse files
committed
Allocation free iterators for LinkedHashMap (nhibernate#3487)
(cherry picked from commit 5675110)
1 parent 6933bf0 commit c3b74df

File tree

14 files changed

+1141
-446
lines changed

14 files changed

+1141
-446
lines changed

src/NHibernate.Test/Async/UtilityTest/LinkedHashMapFixture.cs renamed to src/NHibernate.Test/Async/UtilityTest/LinkHashMapFixture.cs

+23-18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
using System;
12+
using System.Collections;
1213
using System.Collections.Generic;
1314
using System.IO;
1415
using System.Runtime.Serialization.Formatters.Binary;
@@ -19,37 +20,41 @@ namespace NHibernate.Test.UtilityTest
1920
{
2021
using System.Threading.Tasks;
2122
[TestFixture]
22-
public class LinkedHashMapFixtureAsync
23+
public class LinkHashMapFixtureAsync
2324
{
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+
};
2934

3035
private static void Fill(IDictionary<string, Player> lhm)
3136
{
32-
foreach (Player player in players)
37+
foreach (var player in players)
3338
lhm.Add(player.Id, player);
3439
}
3540

3641
[Test, Explicit]
3742
public async Task ShowDiffAsync()
3843
{
3944
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>();
4146
Fill(dict);
4247
Fill(lhm);
4348
// Override the first element
44-
Player o = new Player("12341", "Ovirride");
49+
var o = new Player("12341", "Override");
4550
dict[o.Id] = o;
4651
lhm[o.Id] = o;
4752
await (Console.Out.WriteLineAsync("Dictionary order:"));
4853
foreach (KeyValuePair<string, Player> pair in dict)
4954
{
5055
Console.Out.WriteLine("Key->{0}", pair.Key);
5156
}
52-
await (Console.Out.WriteLineAsync("LinkedHashMap order:"));
57+
await (Console.Out.WriteLineAsync("LinkHashMap order:"));
5358
foreach (KeyValuePair<string, Player> pair in lhm)
5459
{
5560
Console.Out.WriteLine("Key->{0}", pair.Key);
@@ -65,18 +70,18 @@ public async Task PerformanceAsync()
6570

6671
int numOfEntries = Int16.MaxValue;
6772

68-
long[] dictPopulateTicks = new long[numOfRuns];
69-
long[] dictItemTicks = new long[numOfRuns];
73+
var dictPopulateTicks = new long[numOfRuns];
74+
var dictItemTicks = new long[numOfRuns];
7075

71-
long[] linkPopulateTicks = new long[numOfRuns];
72-
long[] linkItemTicks = new long[numOfRuns];
76+
var linkPopulateTicks = new long[numOfRuns];
77+
var linkItemTicks = new long[numOfRuns];
7378

74-
for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
79+
for (var runIndex = 0; runIndex < numOfRuns; runIndex++)
7580
{
7681
string key;
7782
object value;
7883
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>();
8085

8186
long dictStart = DateTime.Now.Ticks;
8287

@@ -118,12 +123,12 @@ public async Task PerformanceAsync()
118123
linked.Clear();
119124
}
120125

121-
for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
126+
for (var runIndex = 0; runIndex < numOfRuns; runIndex++)
122127
{
123128
decimal linkPopulateOverhead = (linkPopulateTicks[runIndex] / (decimal)dictPopulateTicks[runIndex]);
124129
decimal linkItemOverhead = (linkItemTicks[runIndex] / (decimal)dictItemTicks[runIndex]);
125130

126-
string message = string.Format("LinkedHashMap vs Dictionary (Run-{0}) :",runIndex+1);
131+
string message = string.Format("LinkHashMap vs Dictionary (Run-{0}) :",runIndex+1);
127132
message += "\n POPULATE:";
128133
message += "\n\t linked took " + linkPopulateTicks[runIndex] + " ticks.";
129134
message += "\n\t dictionary took " + dictPopulateTicks[runIndex] + " ticks.";

src/NHibernate.Test/NHibernate.Test.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<Compile Include="..\NHibernate\Util\AsyncReaderWriterLock.cs">
5656
<Link>UtilityTest\AsyncReaderWriterLock.cs</Link>
5757
</Compile>
58+
<Compile Include="..\NHibernate\Util\LinkHashMap.cs" Link="UtilityTest\LinkHashMap.cs" />
5859
<Compile Include="..\NHibernate\Collection\Generic\SetHelpers\SetSnapShot.cs">
5960
<Link>UtilityTest\SetSnapShot.cs</Link>
6061
</Compile>

0 commit comments

Comments
 (0)