using System;
using System.IO;
-using System.Text;
+using System.Reflection;
namespace BenchmarksGame
{
class TestHarnessHelpers
{
- public string InputFile;
public int[] expectedCountLetter;
public int[] expectedCountPairs;
public int[] expectedCountFragments;
public int[][] expectedFrequencies;
+ private readonly string resourceName;
- public TestHarnessHelpers(bool bigInput, [System.Runtime.CompilerServices.CallerFilePath] string csFileName = "")
+ public TestHarnessHelpers(bool bigInput)
{
if (bigInput)
{
- InputFile = FindInputFile("knucleotide-input-big.txt", csFileName);
expectedCountLetter = new int[] { 302923, 301375, 198136, 197566 };
expectedCountPairs = new int[] { 91779, 91253, 91225, 90837, 60096, 60030, 59889, 59795, 59756, 59713, 59572, 59557, 39203, 39190, 39081, 39023 };
expectedCountFragments = new int[] { 11765, 3572, 380, 7, 7 };
+ resourceName = "knucleotide-input-big.txt";
}
else
{
- InputFile = FindInputFile("knucleotide-input.txt", csFileName);
expectedCountLetter = new int[] { 1576, 1480, 974, 970 };
expectedCountPairs = new int[] { 496, 480, 470, 420, 316, 315, 310, 302, 298, 292, 273, 272, 202, 201, 185, 167 };
expectedCountFragments = new int[] { 54, 24, 4, 0, 0 };
+ resourceName = "knucleotide-input.txt";
}
expectedFrequencies = new int[][] { expectedCountLetter, expectedCountPairs };
}
- public string FindInputFile(string inputFile, string csFileName)
+ public Stream GetInputStream()
{
- string CoreRoot = System.Environment.GetEnvironmentVariable("CORE_ROOT");
-
- if (CoreRoot == null)
- {
- Console.WriteLine("This benchmark requries CORE_ROOT to be set");
- return null;
- }
-
- // The convention is that the csproj file has the same name as the cs file.
- string projectName = Path.GetFileNameWithoutExtension(csFileName);
- int slashIndex = projectName.LastIndexOfAny(new char[] { '/', '\\' });
- if (slashIndex != -1)
- {
- // csFileName was generated by the C# compiler, which may have run on
- // a different host system with different path separator than the
- // currently executing host, which dictates GetFileNameWithoutExtension's
- // behavior... so hope that the slash here is a cross-host path separator,
- // and chop of what were likely direcotires.
- projectName = projectName.Substring(slashIndex + 1);
- }
-
- // Normal testing -- input file will end up next to the assembly
- // and CoreRoot points at the test overlay dir
- string[] pathPartsNormal = new string[] {
- CoreRoot, "..", "..", "JIT", "Performance",
- "CodeQuality", "BenchmarksGame", "k-nucleotide", projectName, inputFile
- };
-
- string inputPathNormal = Path.Combine(pathPartsNormal);
-
- // Perf testing -- input file will end up next to the assembly
- // and CoreRoot points at this directory
- string[] pathPartsPerf = new string[] { CoreRoot, inputFile };
-
- string inputPathPerf = Path.Combine(pathPartsPerf);
-
- string inputPath = null;
-
- if (File.Exists(inputPathNormal))
- {
- inputPath = inputPathNormal;
- }
- else if (File.Exists(inputPathPerf))
- {
- inputPath = inputPathPerf;
- }
-
- if (inputPath != null)
- {
- Console.WriteLine("Using input file {0}", inputFile);
- }
- else
- {
- throw new Exception($"Unable to find input file {inputFile}. Tried {inputPathNormal} and {inputPathPerf}; csFileName was {csFileName}, so projectName was {projectName}.");
- }
-
- return inputPath;
+ var assembly = typeof(TestHarnessHelpers).GetTypeInfo().Assembly;
+ return assembly.GetManifestResourceStream(resourceName);
}
}
}
{
var helpers = new TestHarnessHelpers(bigInput: false);
- using (var inputFile = new FileStream(helpers.InputFile, FileMode.Open))
+ using (var inputStream = helpers.GetInputStream())
{
- if (!Bench(inputFile, helpers, true))
+ if (!Bench(inputStream, helpers, true))
{
return -1;
}
Benchmark.Iterate(() =>
{
- using (var inputFile = new FileStream(helpers.InputFile, FileMode.Open))
+ using (var inputStream = helpers.GetInputStream())
{
- ok &= Bench(inputFile, helpers, false);
+ ok &= Bench(inputStream, helpers, false);
}
});
Assert.True(ok);
<Compile Include="harness-helpers.cs" />
</ItemGroup>
<ItemGroup>
- <Content Include="knucleotide-input.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
- <Content Include="knucleotide-input-big.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
+ <EmbeddedResource Include="knucleotide-input.txt" />
+ <EmbeddedResource Include="knucleotide-input-big.txt" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
tonum['t'] = 3; tonum['T'] = 3;
tonum['\n'] = 255; tonum['>'] = 255; tonum[255] = 255;
- using (var inputStream = new FileStream(helpers.InputFile, FileMode.Open))
+ using (var inputStream = helpers.GetInputStream())
{
loadThreeData(inputStream);
}
<Compile Include="harness-helpers.cs" />
</ItemGroup>
<ItemGroup>
- <Content Include="knucleotide-input.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
- <Content Include="knucleotide-input-big.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
+ <EmbeddedResource Include="knucleotide-input.txt" />
+ <EmbeddedResource Include="knucleotide-input-big.txt" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
using System;
using System.IO;
-using System.Text;
+using System.Reflection;
namespace BenchmarksGame
{
class TestHarnessHelpers
{
- public string InputFile;
- public int ExpectedLength;
+ public readonly int ExpectedLength;
+ private readonly string resourceName;
- public TestHarnessHelpers(bool bigInput, [System.Runtime.CompilerServices.CallerFilePath] string csFileName = "")
+ public TestHarnessHelpers(bool bigInput)
{
if (bigInput)
{
- InputFile = FindInputFile("regexdna-input25000.txt", csFileName);
ExpectedLength = 136381;
+ resourceName = "regexdna-input25000.txt";
}
else
{
- InputFile = FindInputFile("regexdna-input25.txt", csFileName);
ExpectedLength = 152;
+ resourceName = "regexdna-input25.txt";
}
}
- public string FindInputFile(string inputFile, string csFileName)
+ public Stream GetInputStream()
{
- string CoreRoot = System.Environment.GetEnvironmentVariable("CORE_ROOT");
-
- if (CoreRoot == null)
- {
- Console.WriteLine("This benchmark requries CORE_ROOT to be set");
- return null;
- }
-
- // The convention is that the csproj file has the same name as the cs file.
- string projectName = Path.GetFileNameWithoutExtension(csFileName);
- int slashIndex = projectName.LastIndexOfAny(new char[] { '/', '\\' });
- if (slashIndex != -1)
- {
- // csFileName was generated by the C# compiler, which may have run on
- // a different host system with different path separator than the
- // currently executing host, which dictates GetFileNameWithoutExtension's
- // behavior... so hope that the slash here is a cross-host path separator,
- // and chop of what were likely direcotires.
- projectName = projectName.Substring(slashIndex + 1);
- }
-
- // Normal testing -- input file will end up next to the assembly
- // and CoreRoot points at the test overlay dir
- string[] pathPartsNormal = new string[] {
- CoreRoot, "..", "..", "JIT", "Performance",
- "CodeQuality", "BenchmarksGame", "regex-redux", projectName, inputFile
- };
-
- string inputPathNormal = Path.Combine(pathPartsNormal);
-
- // Perf testing -- input file will end up next to the assembly
- // and CoreRoot points at this directory
- string[] pathPartsPerf = new string[] { CoreRoot, inputFile };
-
- string inputPathPerf = Path.Combine(pathPartsPerf);
-
- string inputPath = null;
-
- if (File.Exists(inputPathNormal))
- {
- inputPath = inputPathNormal;
- }
- else if (File.Exists(inputPathPerf))
- {
- inputPath = inputPathPerf;
- }
-
- if (inputPath != null)
- {
- Console.WriteLine("Using input file {0}", inputFile);
- }
- else
- {
- throw new Exception($"Unable to find input file {inputFile}. Tried {inputPathNormal} and {inputPathPerf}; csFileName was {csFileName}, so projectName was {projectName}.");
- }
-
- return inputPath;
+ var assembly = typeof(TestHarnessHelpers).GetTypeInfo().Assembly;
+ return assembly.GetManifestResourceStream(resourceName);
}
}
}
{
var helpers = new TestHarnessHelpers(bigInput: false);
- using (var inputStream = new FileStream(helpers.InputFile, FileMode.Open))
+ using (var inputStream = helpers.GetInputStream())
using (var input = new StreamReader(inputStream))
{
if (Bench(input, true) != helpers.ExpectedLength)
Benchmark.Iterate(() =>
{
- using (var inputStream = new FileStream(helpers.InputFile, FileMode.Open))
+ using (var inputStream = helpers.GetInputStream())
using (var input = new StreamReader(inputStream))
{
Assert.Equal(helpers.ExpectedLength, Bench(input, false));
<Compile Include="harness-helpers.cs" />
</ItemGroup>
<ItemGroup>
- <Content Include="regexdna-input25.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
- <Content Include="regexdna-input25000.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
+ <EmbeddedResource Include="regexdna-input25.txt" />
+ <EmbeddedResource Include="regexdna-input25000.txt" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
{
var helpers = new TestHarnessHelpers(bigInput: false);
- using (var inputStream = new FileStream(helpers.InputFile, FileMode.Open))
+ using (var inputStream = helpers.GetInputStream())
using (var input = new StreamReader(inputStream))
{
if (Bench(input, true) != helpers.ExpectedLength)
Benchmark.Iterate(() =>
{
- using (var inputStream = new FileStream(helpers.InputFile, FileMode.Open))
+ using (var inputStream = helpers.GetInputStream())
using (var input = new StreamReader(inputStream))
{
Assert.Equal(helpers.ExpectedLength, Bench(input, false));
<Compile Include="harness-helpers.cs" />
</ItemGroup>
<ItemGroup>
- <Content Include="regexdna-input25.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
- <Content Include="regexdna-input25000.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
+ <EmbeddedResource Include="regexdna-input25.txt" />
+ <EmbeddedResource Include="regexdna-input25000.txt" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
using System;
using System.IO;
-using System.Text;
+using System.Reflection;
namespace BenchmarksGame
{
class TestHarnessHelpers
{
- public string InputFile;
public int FileLength;
public string CheckSum;
+ private readonly string resourceName;
public TestHarnessHelpers(bool bigInput, [System.Runtime.CompilerServices.CallerFilePath] string csFileName = "")
{
if (bigInput)
{
- InputFile = FindInputFile("revcomp-input25000.txt", csFileName);
FileLength = 254245;
CheckSum = "61-A4-CC-6D-15-8D-26-77-88-93-4F-E2-29-A2-8D-FB";
+ resourceName = "revcomp-input25000.txt";
}
else
{
- InputFile = FindInputFile("revcomp-input25.txt", csFileName);
FileLength = 333;
CheckSum = "62-45-8E-09-2E-89-A0-69-8C-17-F5-D8-C7-63-5B-50";
+ resourceName = "revcomp-input25.txt";
}
}
- public string FindInputFile(string inputFile, string csFileName)
+ public Stream GetInputStream()
{
- string CoreRoot = System.Environment.GetEnvironmentVariable("CORE_ROOT");
-
- if (CoreRoot == null)
- {
- Console.WriteLine("This benchmark requries CORE_ROOT to be set");
- return null;
- }
-
- // The convention is that the csproj file has the same name as the cs file.
- string projectName = Path.GetFileNameWithoutExtension(csFileName);
- int slashIndex = projectName.LastIndexOfAny(new char[] { '/', '\\' });
- if (slashIndex != -1)
- {
- // csFileName was generated by the C# compiler, which may have run on
- // a different host system with different path separator than the
- // currently executing host, which dictates GetFileNameWithoutExtension's
- // behavior... so hope that the slash here is a cross-host path separator,
- // and chop of what were likely direcotires.
- projectName = projectName.Substring(slashIndex + 1);
- }
-
- // Normal testing -- input file will end up next to the assembly
- // and CoreRoot points at the test overlay dir
- string[] pathPartsNormal = new string[] {
- CoreRoot, "..", "..", "JIT", "Performance",
- "CodeQuality", "BenchmarksGame", "reverse-complement", projectName, inputFile
- };
-
- string inputPathNormal = Path.Combine(pathPartsNormal);
-
- // Perf testing -- input file will end up next to the assembly
- // and CoreRoot points at this directory
- string[] pathPartsPerf = new string[] { CoreRoot, inputFile };
-
- string inputPathPerf = Path.Combine(pathPartsPerf);
-
- string inputPath = null;
-
- if (File.Exists(inputPathNormal))
- {
- inputPath = inputPathNormal;
- }
- else if (File.Exists(inputPathPerf))
- {
- inputPath = inputPathPerf;
- }
-
- if (inputPath != null)
- {
- Console.WriteLine("Using input file {0}", inputFile);
- }
- else
- {
- throw new Exception($"Unable to find input file {inputFile}. Tried {inputPathNormal} and {inputPathPerf}; csFileName was {csFileName}, so projectName was {projectName}.");
- }
-
- return inputPath;
+ var assembly = typeof(TestHarnessHelpers).GetTypeInfo().Assembly;
+ return assembly.GetManifestResourceStream(resourceName);
}
}
}
{
var helpers = new TestHarnessHelpers(bigInput: false);
var outBytes = new byte[helpers.FileLength];
- using (var input = new FileStream(helpers.InputFile, FileMode.Open))
- using (var output = new MemoryStream(outBytes))
+ using (var inputStream = helpers.GetInputStream())
+ using (var outputStream = new MemoryStream(outBytes))
{
- Bench(input, output);
+ Bench(inputStream, outputStream);
}
Console.WriteLine(System.Text.Encoding.UTF8.GetString(outBytes));
if (!MatchesChecksum(outBytes, helpers.CheckSum))
Benchmark.Iterate(() =>
{
- using (var input = new FileStream(helpers.InputFile, FileMode.Open))
- using (var output = new MemoryStream(outBytes))
+ using (var inputStream = helpers.GetInputStream())
+ using (var outputStream = new MemoryStream(outBytes))
{
- Bench(input, output);
+ Bench(inputStream, outputStream);
}
});
<Compile Include="harness-helpers.cs" />
</ItemGroup>
<ItemGroup>
- <Content Include="revcomp-input25.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
- <Content Include="revcomp-input25000.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
+ <EmbeddedResource Include="revcomp-input25.txt" />
+ <EmbeddedResource Include="revcomp-input25000.txt" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
{
var helpers = new TestHarnessHelpers(bigInput: false);
var outBytes = new byte[helpers.FileLength];
- using (var input = new FileStream(helpers.InputFile, FileMode.Open))
- using (var output = new MemoryStream(outBytes))
+ using (var inputStream = helpers.GetInputStream())
+ using (var outputStream = new MemoryStream(outBytes))
{
- Bench(input, output);
+ Bench(inputStream, outputStream);
}
Console.WriteLine(System.Text.Encoding.UTF8.GetString(outBytes));
if (!MatchesChecksum(outBytes, helpers.CheckSum))
Benchmark.Iterate(() =>
{
- var input = new FileStream(helpers.InputFile, FileMode.Open);
- var output = new MemoryStream(outBytes);
+ using (var inputStream = helpers.GetInputStream())
+ using (var outputStream = new MemoryStream(outBytes))
{
- Bench(input, output);
+ Bench(inputStream, outputStream);
}
});
<Compile Include="harness-helpers.cs" />
</ItemGroup>
<ItemGroup>
- <Content Include="revcomp-input25.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
- <Content Include="revcomp-input25000.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
+ <EmbeddedResource Include="revcomp-input25.txt" />
+ <EmbeddedResource Include="revcomp-input25000.txt" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>