-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: merged compression and decompression
- Loading branch information
Showing
4 changed files
with
106 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,29 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace DotFastLZ.Benchmark; | ||
namespace DotFastLZ.Benchmark; | ||
|
||
public class BenchmarkResult | ||
{ | ||
public const int CollSize = 4; | ||
public string Name; | ||
public int Times; | ||
public Stopwatch ElapsedWatch; | ||
public long SourceBytes; | ||
public long DestBytes; | ||
|
||
public static double CalculateCompressionSpeed(long size, TimeSpan timeSpan) | ||
{ | ||
// MB/s | ||
return (double)size / (1024 * 1024) / timeSpan.TotalSeconds; | ||
} | ||
|
||
public double ComputeRate() | ||
{ | ||
return DestBytes / (double)SourceBytes * 100; | ||
} | ||
|
||
public string ToRateString() | ||
{ | ||
return $"{ComputeRate():F2}"; | ||
} | ||
|
||
public double ComputeSpeed() | ||
{ | ||
return CalculateCompressionSpeed(DestBytes, ElapsedWatch.Elapsed); | ||
} | ||
|
||
public string ToSpeedString() | ||
{ | ||
return $"{ComputeSpeed():F2}"; | ||
} | ||
public BenchmarkSpeed Compression; | ||
public BenchmarkSpeed Decompression; | ||
|
||
public override string ToString() | ||
{ | ||
var result = ""; | ||
result += $"{Name}\n"; | ||
result += $" - times: {Times}\n"; | ||
result += $" - source bytes: {SourceBytes / Times}\n"; | ||
result += $" - compression bytes: {DestBytes / Times}\n"; | ||
result += $" - compression rate: {ComputeRate():F2}%\n"; | ||
result += $" - compression speed: {ComputeSpeed():F2} MB/s\n"; | ||
result += $" - source bytes: {Compression.InputBytes / Times}\n"; | ||
result += $" - compression bytes: {Compression.OutputBytes / Times}\n"; | ||
result += $" - compression rate: {Compression.ComputeRate():F2}%\n"; | ||
result += $" - compression speed: {Compression.ComputeSpeed():F2} MB/s\n"; | ||
result += $" - decompression speed: {Decompression.ComputeSpeed():F2} MB/s\n"; | ||
|
||
return result; | ||
} | ||
|
||
public double ComputeTotalSpeed() | ||
{ | ||
return Compression.ComputeSpeed() + Decompression.ComputeSpeed(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace DotFastLZ.Benchmark; | ||
|
||
public struct BenchmarkSpeed | ||
{ | ||
public Stopwatch ElapsedWatch; | ||
public long InputBytes; | ||
public long OutputBytes; | ||
|
||
public double ComputeRate() | ||
{ | ||
return OutputBytes / (double)InputBytes * 100; | ||
} | ||
|
||
public string ToRateString() | ||
{ | ||
return $"{ComputeRate():F2}"; | ||
} | ||
|
||
public double ComputeSpeed() | ||
{ | ||
return CalculateCompressionSpeed(OutputBytes, ElapsedWatch.Elapsed); | ||
} | ||
|
||
public static double CalculateCompressionSpeed(long size, TimeSpan timeSpan) | ||
{ | ||
// MB/s | ||
return (double)size / (1024 * 1024) / timeSpan.TotalSeconds; | ||
} | ||
|
||
public string ToSpeedString() | ||
{ | ||
return $"{ComputeSpeed():F2}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters