File tree Expand file tree Collapse file tree 6 files changed +213
-0
lines changed
benchmark/ICSharpCode.SharpZipLib.Benchmark Expand file tree Collapse file tree 6 files changed +213
-0
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using BenchmarkDotNet . Attributes ;
3+
4+ namespace ICSharpCode . SharpZipLib . Benchmark . Checksum
5+ {
6+ [ Config ( typeof ( MultipleRuntimes ) ) ]
7+ public class Adler32
8+ {
9+ private const int ChunkCount = 256 ;
10+ private const int ChunkSize = 1024 * 1024 ;
11+ private const int N = ChunkCount * ChunkSize ;
12+ private readonly byte [ ] data ;
13+
14+ public Adler32 ( )
15+ {
16+ data = new byte [ N ] ;
17+ new Random ( 1 ) . NextBytes ( data ) ;
18+ }
19+
20+ [ Benchmark ]
21+ public long Adler32LargeUpdate ( )
22+ {
23+ var adler32 = new ICSharpCode . SharpZipLib . Checksum . Adler32 ( ) ;
24+ adler32 . Update ( data ) ;
25+ return adler32 . Value ;
26+ }
27+
28+ [ Benchmark ]
29+ public long Adler32ChunkedUpdate ( )
30+ {
31+ var adler32 = new ICSharpCode . SharpZipLib . Checksum . Adler32 ( ) ;
32+
33+ for ( int i = 0 ; i < ChunkCount ; i ++ )
34+ {
35+ var segment = new ArraySegment < byte > ( data , ChunkSize * i , ChunkSize ) ;
36+ adler32 . Update ( segment ) ;
37+ }
38+
39+ return adler32 . Value ;
40+ }
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ using System ;
2+ using BenchmarkDotNet . Attributes ;
3+
4+ namespace ICSharpCode . SharpZipLib . Benchmark . Checksum
5+ {
6+ [ Config ( typeof ( MultipleRuntimes ) ) ]
7+ public class BZip2Crc
8+ {
9+ private const int ChunkCount = 256 ;
10+ private const int ChunkSize = 1024 * 1024 ;
11+ private const int N = ChunkCount * ChunkSize ;
12+ private readonly byte [ ] data ;
13+
14+ public BZip2Crc ( )
15+ {
16+ data = new byte [ N ] ;
17+ new Random ( 1 ) . NextBytes ( data ) ;
18+ }
19+
20+ [ Benchmark ]
21+ public long BZip2CrcLargeUpdate ( )
22+ {
23+ var bzipCrc = new ICSharpCode . SharpZipLib . Checksum . BZip2Crc ( ) ;
24+ bzipCrc . Update ( data ) ;
25+ return bzipCrc . Value ;
26+ }
27+
28+ [ Benchmark ]
29+ public long BZip2CrcChunkedUpdate ( )
30+ {
31+ var bzipCrc = new ICSharpCode . SharpZipLib . Checksum . BZip2Crc ( ) ;
32+
33+ for ( int i = 0 ; i < ChunkCount ; i ++ )
34+ {
35+ var segment = new ArraySegment < byte > ( data , ChunkSize * i , ChunkSize ) ;
36+ bzipCrc . Update ( segment ) ;
37+ }
38+
39+ return bzipCrc . Value ;
40+ }
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ using System ;
2+ using BenchmarkDotNet . Attributes ;
3+
4+ namespace ICSharpCode . SharpZipLib . Benchmark . Checksum
5+ {
6+ [ Config ( typeof ( MultipleRuntimes ) ) ]
7+ public class Crc32
8+ {
9+ private const int ChunkCount = 256 ;
10+ private const int ChunkSize = 1024 * 1024 ;
11+ private const int N = ChunkCount * ChunkSize ;
12+ private readonly byte [ ] data ;
13+
14+ public Crc32 ( )
15+ {
16+ data = new byte [ N ] ;
17+ new Random ( 1 ) . NextBytes ( data ) ;
18+ }
19+
20+ [ Benchmark ]
21+ public long Crc32LargeUpdate ( )
22+ {
23+ var crc32 = new ICSharpCode . SharpZipLib . Checksum . Crc32 ( ) ;
24+ crc32 . Update ( data ) ;
25+ return crc32 . Value ;
26+ }
27+
28+ [ Benchmark ]
29+ public long Crc32ChunkedUpdate ( )
30+ {
31+ var crc32 = new ICSharpCode . SharpZipLib . Checksum . Crc32 ( ) ;
32+
33+ for ( int i = 0 ; i < ChunkCount ; i ++ )
34+ {
35+ var segment = new ArraySegment < byte > ( data , ChunkSize * i , ChunkSize ) ;
36+ crc32 . Update ( segment ) ;
37+ }
38+
39+ return crc32 . Value ;
40+ }
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ <Project Sdk =" Microsoft.NET.Sdk" >
2+
3+ <PropertyGroup >
4+ <OutputType >Exe</OutputType >
5+ <TargetFrameworks >netcoreapp2.1;net461</TargetFrameworks >
6+ </PropertyGroup >
7+
8+ <ItemGroup >
9+ <PackageReference Include =" BenchmarkDotNet" >
10+ <Version >0.11.4</Version >
11+ </PackageReference >
12+ </ItemGroup >
13+
14+ <ItemGroup >
15+ <ProjectReference Include =" ..\..\src\ICSharpCode.SharpZipLib\ICSharpCode.SharpZipLib.csproj" />
16+ </ItemGroup >
17+
18+ </Project >
Original file line number Diff line number Diff line change 1+ using System ;
2+ using BenchmarkDotNet ;
3+ using BenchmarkDotNet . Configs ;
4+ using BenchmarkDotNet . Jobs ;
5+ using BenchmarkDotNet . Running ;
6+ using BenchmarkDotNet . Toolchains . CsProj ;
7+
8+ namespace ICSharpCode . SharpZipLib . Benchmark
9+ {
10+ public class MultipleRuntimes : ManualConfig
11+ {
12+ public MultipleRuntimes ( )
13+ {
14+ Add ( Job . Default . With ( CsProjClassicNetToolchain . Net471 ) . AsBaseline ( ) ) ; // NET 4.7.1
15+ Add ( Job . Default . With ( CsProjCoreToolchain . NetCoreApp21 ) ) ; // .NET Core 2.1
16+ //Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp30)); // .NET Core 3.0
17+ }
18+ }
19+
20+ class Program
21+ {
22+ static void Main ( string [ ] args )
23+ {
24+ //var summary = BenchmarkRunner.Run<Checksums>();
25+ BenchmarkSwitcher . FromAssembly ( typeof ( Program ) . Assembly ) . Run ( args ) ;
26+ }
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . IO ;
3+ using BenchmarkDotNet . Attributes ;
4+
5+ namespace ICSharpCode . SharpZipLib . Benchmark . Zip
6+ {
7+ [ Config ( typeof ( MultipleRuntimes ) ) ]
8+ public class ZipOutputStream
9+ {
10+ private const int ChunkCount = 64 ;
11+ private const int ChunkSize = 1024 * 1024 ;
12+ private const int N = ChunkCount * ChunkSize ;
13+
14+ byte [ ] outputBuffer ;
15+ byte [ ] inputBuffer ;
16+
17+ public ZipOutputStream ( )
18+ {
19+ inputBuffer = new byte [ ChunkSize ] ;
20+ outputBuffer = new byte [ N ] ;
21+ }
22+
23+ [ Benchmark ]
24+ public long WriteZipOutputStream ( )
25+ {
26+ using ( var memoryStream = new MemoryStream ( outputBuffer ) )
27+ {
28+ var zipOutputStream = new SharpZipLib . Zip . ZipOutputStream ( memoryStream ) ;
29+ zipOutputStream . PutNextEntry ( new SharpZipLib . Zip . ZipEntry ( "0" ) ) ;
30+
31+ for ( int i = 0 ; i < ChunkCount ; i ++ )
32+ {
33+ zipOutputStream . Write ( inputBuffer , 0 , inputBuffer . Length ) ;
34+ }
35+
36+ return memoryStream . Position ;
37+ }
38+ }
39+
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments