本文整理汇总了C#中ICompressor.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ICompressor.GetType方法的具体用法?C# ICompressor.GetType怎么用?C# ICompressor.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICompressor
的用法示例。
在下文中一共展示了ICompressor.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Performance
public void Performance(ICompressor compressor)
{
results.Add("---------" + compressor.GetType() + "---------");
byte[] indata = Encoding.UTF8.GetBytes(testData);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
byte[] result = null;
foreach (var i in Enumerable.Range(0,100))
{
result = compressor.Compress(indata);
}
stopwatch.Stop();
long ticks = stopwatch.ElapsedTicks;
results.Add("Compress: " + ticks);
stopwatch.Reset();
stopwatch.Start();
byte[] resurrected;
foreach (var i in Enumerable.Range(0, 100))
{
resurrected = compressor.Decompress(result);
}
stopwatch.Stop();
ticks = stopwatch.ElapsedTicks;
results.Add("Decompress: " + ticks);
results.Add("Compression: " + result.Length / (1.0 * indata.Length));
}
示例2: UploadFileWithCompress
public static MongoGridFSFileInfo UploadFileWithCompress(this IMongoRepository repository, ICompressor compressor, byte[] data,
string remoteFilename) {
compressor.ShouldNotBeNull("compressor");
var entry = new CompressedFileItem(compressor.GetType(), compressor.Compress(data));
using(var stream = new MemoryStream(FileSerializer.Serialize(entry))) {
return repository.UploadFile(remoteFilename, stream);
}
}
示例3: Benchmark
private void Benchmark(ICompressor compressor)
{
Console.WriteLine("Target compression ratio: {0:P1}", _dataCreator.CompressionRatio);
Console.WriteLine();
const int batch = 10;
Console.WriteLine("Benchmark of {0}:", compressor.GetType().Name);
WarmUpCompressor(compressor);
DoBenchmark(compressor, 4 * 1024, batch);
DoBenchmark(compressor, 32 * 1024, batch);
DoBenchmark(compressor, 64 * 1024, batch);
DoBenchmark(compressor, 128 * 1024, batch);
DoBenchmark(compressor, 256 * 1024, batch);
DoBenchmark(compressor, 512 * 1024, batch);
DoBenchmark(compressor, 1024 * 1024, batch);
DoBenchmark(compressor, 2048 * 1024, batch);
DoBenchmark(compressor, 5120 * 1024, batch);
DoBenchmark(compressor, 10240 * 1024, batch);
DoBenchmark(compressor, 20480 * 1024, batch);
Console.WriteLine("---------------------------------------------");
}