Cache property lookups for the object parsing
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Parsers\LeafInputCsvParserTests.cs" />
|
||||
<Compile Include="Remote\PiscalSshClientTests.cs" />
|
||||
<Compile Include="Utility\MemoizerTests.cs" />
|
||||
<Compile Include="Utility\StringExtensionsTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using LeafWeb.Core.Entities;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.Core.Parsers;
|
||||
using LeafWeb.Core.Utility;
|
||||
using NUnit.Framework;
|
||||
@@ -21,5 +23,28 @@ namespace LeafWeb.Core.Tests.Parsers
|
||||
|
||||
Assert.That(leafGasComparisons.Length, Is.EqualTo(6));
|
||||
}
|
||||
|
||||
//[Test, Explicit]
|
||||
public void Parse_Timer()
|
||||
{
|
||||
var smallFileInfo = FileUtility.GetContentFile(ContentDirectory, "leafgascomparison.csv");
|
||||
var largeFileInfo = FileUtility.GetContentFile(@"c:\temp\", "20160411095955C3_leafgascomparison.csv");
|
||||
var timer = new Stopwatch();
|
||||
|
||||
timer.Start();
|
||||
using (var parser = new LeafGasComparisonParser(smallFileInfo))
|
||||
parser.Parse();
|
||||
timer.Stop();
|
||||
|
||||
Console.WriteLine($"{timer.ElapsedMilliseconds}");
|
||||
|
||||
timer.Reset();
|
||||
timer.Start();
|
||||
using (var parser = new LeafGasComparisonParser(largeFileInfo))
|
||||
parser.Parse();
|
||||
timer.Stop();
|
||||
|
||||
Console.WriteLine($"{timer.ElapsedMilliseconds}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using LeafWeb.Core.Utility;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace LeafWeb.Core.Tests.Utility
|
||||
{
|
||||
[TestFixture]
|
||||
public class MemoizerTests
|
||||
{
|
||||
[Test]
|
||||
public void ThreadsafeMemoize_Test()
|
||||
{
|
||||
Func<string, int, string> func = (a1, a2) => a1 + a2.ToString();
|
||||
|
||||
var funcMem = Memoizer.ThreadsafeMemoize(func);
|
||||
|
||||
var result = funcMem("hi", 1);
|
||||
Assert.That(result, Is.EqualTo("hi1"));
|
||||
|
||||
var resultAgain = funcMem("hi", 1);
|
||||
Assert.That(resultAgain, Is.EqualTo("hi1"));
|
||||
|
||||
var differentResult = funcMem("this", 2);
|
||||
Assert.That(differentResult, Is.EqualTo("this2"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user