Skip to content

Allocation free iterators for LinkedHashMap #3487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
Expand All @@ -19,37 +20,41 @@ namespace NHibernate.Test.UtilityTest
{
using System.Threading.Tasks;
[TestFixture]
public class LinkedHashMapFixtureAsync
public class LinkHashMapFixtureAsync
{
private static readonly Player[] players = {
new Player("12341", "Boeta Dippenaar"), new Player("23432", "Gary Kirsten"),
new Player("23411", "Graeme Smith"), new Player("55221", "Jonty Rhodes"),
new Player("61234", "Monde Zondeki"), new Player("23415", "Paul Adams")
};
private static readonly Player[] players =
{
new Player("12341", "Boeta Dippenaar"),
new Player("23432", "Gary Kirsten"),
new Player("23411", "Graeme Smith"),
new Player("55221", "Jonty Rhodes"),
new Player("61234", "Monde Zondeki"),
new Player("23415", "Paul Adams")
};

private static void Fill(IDictionary<string, Player> lhm)
{
foreach (Player player in players)
foreach (var player in players)
lhm.Add(player.Id, player);
}

[Test, Explicit]
public async Task ShowDiffAsync()
{
IDictionary<string, Player> dict = new Dictionary<string, Player>();
IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
IDictionary<string, Player> lhm = new LinkHashMap<string, Player>();
Fill(dict);
Fill(lhm);
// Override the first element
Player o = new Player("12341", "Ovirride");
var o = new Player("12341", "Override");
dict[o.Id] = o;
lhm[o.Id] = o;
await (Console.Out.WriteLineAsync("Dictionary order:"));
foreach (KeyValuePair<string, Player> pair in dict)
{
Console.Out.WriteLine("Key->{0}", pair.Key);
}
await (Console.Out.WriteLineAsync("LinkedHashMap order:"));
await (Console.Out.WriteLineAsync("LinkHashMap order:"));
foreach (KeyValuePair<string, Player> pair in lhm)
{
Console.Out.WriteLine("Key->{0}", pair.Key);
Expand All @@ -65,18 +70,18 @@ public async Task PerformanceAsync()

int numOfEntries = Int16.MaxValue;

long[] dictPopulateTicks = new long[numOfRuns];
long[] dictItemTicks = new long[numOfRuns];
var dictPopulateTicks = new long[numOfRuns];
var dictItemTicks = new long[numOfRuns];

long[] linkPopulateTicks = new long[numOfRuns];
long[] linkItemTicks = new long[numOfRuns];
var linkPopulateTicks = new long[numOfRuns];
var linkItemTicks = new long[numOfRuns];

for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
for (var runIndex = 0; runIndex < numOfRuns; runIndex++)
{
string key;
object value;
IDictionary<string, object> dictionary = new Dictionary<string, object>();
IDictionary<string, object> linked = new LinkedHashMap<string, object>();
IDictionary<string, object> linked = new LinkHashMap<string, object>();

long dictStart = DateTime.Now.Ticks;

Expand Down Expand Up @@ -118,12 +123,12 @@ public async Task PerformanceAsync()
linked.Clear();
}

for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
for (var runIndex = 0; runIndex < numOfRuns; runIndex++)
{
decimal linkPopulateOverhead = (linkPopulateTicks[runIndex] / (decimal)dictPopulateTicks[runIndex]);
decimal linkItemOverhead = (linkItemTicks[runIndex] / (decimal)dictItemTicks[runIndex]);

string message = string.Format("LinkedHashMap vs Dictionary (Run-{0}) :",runIndex+1);
string message = string.Format("LinkHashMap vs Dictionary (Run-{0}) :",runIndex+1);
message += "\n POPULATE:";
message += "\n\t linked took " + linkPopulateTicks[runIndex] + " ticks.";
message += "\n\t dictionary took " + dictPopulateTicks[runIndex] + " ticks.";
Expand Down
1 change: 1 addition & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="..\NHibernate\Util\AsyncReaderWriterLock.cs">
<Link>UtilityTest\AsyncReaderWriterLock.cs</Link>
</Compile>
<Compile Include="..\NHibernate\Util\LinkHashMap.cs" Link="UtilityTest\LinkHashMap.cs" />
<Compile Include="..\NHibernate\Collection\Generic\SetHelpers\SetSnapShot.cs">
<Link>UtilityTest\SetSnapShot.cs</Link>
</Compile>
Expand Down
Loading