Permalink
Browse files

Minor improvements. Performance test for Bzip2 which is slow!

  • Loading branch information...
1 parent ceca8e8 commit 84c886d121435534b5bec30dfdfe6fa8c8698b83 @jfreilly jfreilly committed Nov 21, 2007
View
@@ -10,9 +10,9 @@
[assembly: AssemblyTitle("SharpZipTests")]
[assembly: AssemblyDescription("Nunit test suite for #Zip library")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("")]
-[assembly: AssemblyCopyright("")]
+[assembly: AssemblyCompany("ICSharpCode.net")]
+[assembly: AssemblyProduct("#ZipLibrary")]
+[assembly: AssemblyCopyright("Copyright 2001-2007 Mike Krueger, John Reilly")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -23,7 +23,8 @@
// You can specify all values by your own or you can build default build and revision
// numbers with the '*' character (the default):
-[assembly: AssemblyVersion("0.85.4.369")]
+[assembly: AssemblyVersion("0.85.5.407")]
+[assembly: AssemblyInformationalVersionAttribute("0.85.5")]
// The following attributes specify the key for the sign of your assembly. See the
// .NET Framework documentation for more information about signing.
View
@@ -1,8 +1,11 @@
using System;
using System.IO;
+using System.Threading;
using ICSharpCode.SharpZipLib.BZip2;
+using ICSharpCode.SharpZipLib.Tests.TestSupport;
+
using NUnit.Framework;
namespace ICSharpCode.SharpZipLib.Tests.BZip2
@@ -84,5 +87,104 @@ public void CreateEmptyArchive()
Assert.AreEqual(pos, 0);
}
}
+
+ BZip2OutputStream outStream_;
+ BZip2InputStream inStream_;
+ WindowedStream window_;
+ long readTarget_;
+ long writeTarget_;
+
+ [Test]
+ [Category("BZip2")]
+ public void Performance()
+ {
+ window_ = new WindowedStream(0x150000);
+
+ outStream_ = new BZip2OutputStream(window_, 1);
+
+ long target = 0x10000000;
+ readTarget_ = writeTarget_ = target;
+
+ Thread reader = new Thread(Reader);
+ reader.Name = "Reader";
+
+ Thread writer = new Thread(Writer);
+ writer.Name = "Writer";
+
+ DateTime startTime = DateTime.Now;
+ writer.Start();
+
+ inStream_ = new BZip2InputStream(window_);
+
+ reader.Start();
+
+ writer.Join();
+ reader.Join();
+
+ DateTime endTime = DateTime.Now;
+ TimeSpan span = endTime - startTime;
+ Console.WriteLine("Time {0} throughput {1} KB/Sec", span, (target / 1024) / span.TotalSeconds);
+
+ }
+
+ void Reader()
+ {
+ const int Size = 8192;
+ int readBytes = 1;
+ byte[] buffer = new byte[Size];
+
+ long passifierLevel = readTarget_ - 0x10000000;
+
+ while ((readTarget_ > 0) && (readBytes > 0))
+ {
+ int count = Size;
+ if (count > readTarget_)
+ {
+ count = (int)readTarget_;
+ }
+
+ readBytes = inStream_.Read(buffer, 0, count);
+ readTarget_ -= readBytes;
+
+ if (readTarget_ <= passifierLevel)
+ {
+ Console.WriteLine("Reader {0} bytes remaining", readTarget_);
+ passifierLevel = readTarget_ - 0x10000000;
+ }
+ }
+
+ Assert.IsTrue(window_.IsClosed, "Window should be closed");
+
+ // This shouldnt read any data but should read the footer
+ readBytes = inStream_.Read(buffer, 0, 1);
+ Assert.AreEqual(0, readBytes, "Stream should be empty");
+ Assert.AreEqual(0, window_.Length, "Window should be closed");
+ inStream_.Close();
+ }
+
+ void WriteTargetBytes()
+ {
+ const int Size = 8192;
+
+ byte[] buffer = new byte[Size];
+
+ while (writeTarget_ > 0)
+ {
+ int thisTime = Size;
+ if (thisTime > writeTarget_)
+ {
+ thisTime = (int)writeTarget_;
+ }
+
+ outStream_.Write(buffer, 0, thisTime);
+ writeTarget_ -= thisTime;
+ }
+ }
+
+ void Writer()
+ {
+ WriteTargetBytes();
+ outStream_.Close();
+ }
}
}
@@ -212,7 +212,7 @@ public void CloseDeflatorWithNestedUsing()
[Category("Base")]
public void DeflatorStreamOwnership()
{
- MemoryStreamEx memStream = new MemoryStreamEx();
+ TrackedMemoryStream memStream = new TrackedMemoryStream();
DeflaterOutputStream s = new DeflaterOutputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
@@ -223,7 +223,7 @@ public void DeflatorStreamOwnership()
Assert.IsTrue(memStream.IsClosed, "Should be closed after parent owner close");
Assert.IsTrue(memStream.IsDisposed, "Should be disposed after parent owner close");
- memStream = new MemoryStreamEx();
+ memStream = new TrackedMemoryStream();
s = new DeflaterOutputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
@@ -241,7 +241,7 @@ public void DeflatorStreamOwnership()
[Category("Base")]
public void InflatorStreamOwnership()
{
- MemoryStreamEx memStream = new MemoryStreamEx();
+ TrackedMemoryStream memStream = new TrackedMemoryStream();
InflaterInputStream s = new InflaterInputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
@@ -252,7 +252,7 @@ public void InflatorStreamOwnership()
Assert.IsTrue(memStream.IsClosed, "Should be closed after parent owner close");
Assert.IsTrue(memStream.IsDisposed, "Should be disposed after parent owner close");
- memStream = new MemoryStreamEx();
+ memStream = new TrackedMemoryStream();
s = new InflaterInputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
View
@@ -120,7 +120,7 @@ public void ZeroLengthInputStream()
[Category("GZip")]
public void OutputStreamOwnership()
{
- MemoryStreamEx memStream = new MemoryStreamEx();
+ TrackedMemoryStream memStream = new TrackedMemoryStream();
GZipOutputStream s = new GZipOutputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
@@ -131,7 +131,7 @@ public void OutputStreamOwnership()
Assert.IsTrue(memStream.IsClosed, "Should be closed after parent owner close");
Assert.IsTrue(memStream.IsDisposed, "Should be disposed after parent owner close");
- memStream = new MemoryStreamEx();
+ memStream = new TrackedMemoryStream();
s = new GZipOutputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
@@ -148,7 +148,7 @@ public void OutputStreamOwnership()
[Category("GZip")]
public void InputStreamOwnership()
{
- MemoryStreamEx memStream = new MemoryStreamEx();
+ TrackedMemoryStream memStream = new TrackedMemoryStream();
GZipInputStream s = new GZipInputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
@@ -159,7 +159,7 @@ public void InputStreamOwnership()
Assert.IsTrue(memStream.IsClosed, "Should be closed after parent owner close");
Assert.IsTrue(memStream.IsDisposed, "Should be disposed after parent owner close");
- memStream = new MemoryStreamEx();
+ memStream = new TrackedMemoryStream();
s = new GZipInputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
@@ -35,23 +35,19 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<StartAction>Program</StartAction>
- <StartProgram>C:\Program Files\NUnit-Net-2.0 2.2.9\bin\nunit-gui.exe</StartProgram>
+ <StartProgram>..\..\..\..\..\..\..\..\..\Bin\Nunit\bin\nunit.exe</StartProgram>
<StartArguments>SharpZipLibTests.dll</StartArguments>
- <StartWorkingDirectory>bin\Debug\</StartWorkingDirectory>
+ <StartWorkingDirectory>.</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<StartArguments>SharpZipLibTests.dll</StartArguments>
</PropertyGroup>
<ItemGroup>
- <Reference Include="nunit.framework, Version=2.4.1.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\..\..\..\..\..\..\Bin\Nunit-2.4\bin\nunit.framework.dll</HintPath>
- </Reference>
- </ItemGroup>
- <ItemGroup>
<Compile Include="AssemblyInfo.cs" />
+ <Compile Include="Core\Core.cs" />
<Compile Include="TestSupport\RingBuffer.cs" />
<Compile Include="TestSupport\Streams.cs" />
+ <Compile Include="TestSupport\ZipTesting.cs" />
<Compile Include="Zip\ZipTests.cs" />
<Compile Include="BZip2\Bzip2Tests.cs" />
<Compile Include="GZip\GZipTests.cs" />
@@ -64,5 +60,14 @@
<Name>ICSharpCode.SharpZLib</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\..\..\..\..\..\..\Bin\Nunit\bin\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>
Oops, something went wrong.

0 comments on commit 84c886d

Please sign in to comment.