2015-11-30 23:00:47 +00:00
|
|
|
// /***************************************************************************
|
2015-11-27 10:32:54 +00:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Benchmark.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-11-27 10:32:54 +00:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Verbs.
|
2015-11-27 10:32:54 +00:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Implements the 'benchmark' verb.
|
2015-11-27 10:32:54 +00:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2015-11-27 10:32:54 +00:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2017-05-27 23:14:55 +01:00
|
|
|
using System.Collections.Generic;
|
2019-01-05 19:50:56 +00:00
|
|
|
using DiscImageChef.CommonTypes.Enums;
|
2017-05-27 23:14:55 +01:00
|
|
|
using DiscImageChef.Console;
|
2017-12-19 19:33:46 +00:00
|
|
|
using DiscImageChef.Core;
|
2019-01-05 16:59:23 +00:00
|
|
|
using Mono.Options;
|
2015-11-27 10:32:54 +00:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Commands
|
|
|
|
|
{
|
2019-01-05 16:59:23 +00:00
|
|
|
class BenchmarkCommand : Command
|
2015-11-27 10:32:54 +00:00
|
|
|
{
|
2019-01-05 16:59:23 +00:00
|
|
|
int blockSize = 512;
|
|
|
|
|
int bufferSize = 128;
|
|
|
|
|
bool showHelp;
|
|
|
|
|
|
|
|
|
|
public BenchmarkCommand() : base("benchmark", "Benchmarks hashing and entropy calculation.")
|
|
|
|
|
{
|
|
|
|
|
Options = new OptionSet
|
|
|
|
|
{
|
|
|
|
|
$"{MainClass.AssemblyTitle} {MainClass.AssemblyVersion?.InformationalVersion}",
|
|
|
|
|
$"{MainClass.AssemblyCopyright}",
|
|
|
|
|
"",
|
|
|
|
|
$"usage: DiscImageChef {Name} [OPTIONS]",
|
|
|
|
|
"",
|
|
|
|
|
Help,
|
|
|
|
|
{"block-size|b=", "Block size.", (int i) => blockSize = i},
|
|
|
|
|
{"buffer-size|s=", "Buffer size in mebibytes.", (int i) => bufferSize = i},
|
|
|
|
|
{"help|h|?", "Show this message and exit.", v => showHelp = v != null}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Invoke(IEnumerable<string> arguments)
|
2015-11-27 10:32:54 +00:00
|
|
|
{
|
2019-01-05 16:59:23 +00:00
|
|
|
List<string> extra = Options.Parse(arguments);
|
|
|
|
|
|
|
|
|
|
if(showHelp)
|
|
|
|
|
{
|
|
|
|
|
Options.WriteOptionDescriptions(CommandSet.Out);
|
2019-01-05 19:50:56 +00:00
|
|
|
return (int)ErrorNumber.HelpRequested;
|
2019-01-05 16:59:23 +00:00
|
|
|
}
|
2017-05-27 23:14:55 +01:00
|
|
|
|
2019-01-05 16:59:23 +00:00
|
|
|
MainClass.PrintCopyright();
|
|
|
|
|
if(MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
|
|
|
|
|
if(MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
|
2019-01-05 20:21:57 +00:00
|
|
|
Statistics.AddCommand("benchmark");
|
2019-01-05 16:59:23 +00:00
|
|
|
|
|
|
|
|
if(extra.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.ErrorWriteLine("Too many arguments.");
|
2019-01-05 19:50:56 +00:00
|
|
|
return (int)ErrorNumber.UnexpectedArgumentCount;
|
2019-01-05 16:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Benchmark command", "--debug={0}", MainClass.Debug);
|
|
|
|
|
DicConsole.DebugWriteLine("Benchmark command", "--verbose={0}", MainClass.Verbose);
|
|
|
|
|
|
|
|
|
|
Benchmark.InitProgressEvent += Progress.InitProgress;
|
|
|
|
|
Benchmark.UpdateProgressEvent += Progress.UpdateProgress;
|
|
|
|
|
Benchmark.EndProgressEvent += Progress.EndProgress;
|
|
|
|
|
|
|
|
|
|
BenchmarkResults results = Benchmark.Do(bufferSize * 1024 * 1024, blockSize);
|
2017-05-27 23:14:55 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
DicConsole.WriteLine("Took {0} seconds to fill buffer, {1:F3} MiB/sec.", results.FillTime,
|
|
|
|
|
results.FillSpeed);
|
|
|
|
|
DicConsole.WriteLine("Took {0} seconds to read buffer, {1:F3} MiB/sec.", results.ReadTime,
|
|
|
|
|
results.ReadSpeed);
|
|
|
|
|
DicConsole.WriteLine("Took {0} seconds to entropy buffer, {1:F3} MiB/sec.", results.EntropyTime,
|
|
|
|
|
results.EntropySpeed);
|
2017-05-27 23:14:55 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(KeyValuePair<string, BenchmarkEntry> entry in results.Entries)
|
|
|
|
|
DicConsole.WriteLine("Took {0} seconds to {1} buffer, {2:F3} MiB/sec.", entry.Value.TimeSpan, entry.Key,
|
|
|
|
|
entry.Value.Speed);
|
2017-05-27 23:14:55 +01:00
|
|
|
|
2018-10-08 23:32:00 +01:00
|
|
|
DicConsole.WriteLine("Took {0} seconds to do all algorithms at the same time, {1:F3} MiB/sec.",
|
2017-12-20 17:15:26 +00:00
|
|
|
results.TotalTime, results.TotalSpeed);
|
2018-10-08 23:32:00 +01:00
|
|
|
DicConsole.WriteLine("Took {0} seconds to do all algorithms sequentially, {1:F3} MiB/sec.",
|
2017-12-20 17:15:26 +00:00
|
|
|
results.SeparateTime, results.SeparateSpeed);
|
2017-05-27 23:14:55 +01:00
|
|
|
|
|
|
|
|
DicConsole.WriteLine();
|
2017-12-20 17:15:26 +00:00
|
|
|
DicConsole.WriteLine("Max memory used is {0} bytes", results.MaxMemory);
|
|
|
|
|
DicConsole.WriteLine("Min memory used is {0} bytes", results.MinMemory);
|
2017-05-27 23:14:55 +01:00
|
|
|
|
2019-01-05 19:50:56 +00:00
|
|
|
return (int)ErrorNumber.NoError;
|
2015-11-30 22:28:42 +00:00
|
|
|
}
|
2015-11-27 10:32:54 +00:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|