本文整理汇总了C#中Benchmark类的典型用法代码示例。如果您正苦于以下问题:C# Benchmark类的具体用法?C# Benchmark怎么用?C# Benchmark使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Benchmark类属于命名空间,在下文中一共展示了Benchmark类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BenchmarkClassicFlow
public BenchmarkClassicFlow(Benchmark benchmark, IBenchmarkLogger logger)
{
this.benchmark = benchmark;
generator = new BenchmarkClassicGenerator(logger);
builder = new BenchmarkClassicBuilder(logger);
executor = new BenchmarkClassicExecutor(benchmark, logger);
}
示例2: Build
/// <summary>
/// generates project.lock.json that tells compiler where to take dlls and source from
/// and builds executable and copies all required dll's
/// </summary>
public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
{
if (!ExecuteCommand("restore", generateResult.DirectoryPath, logger))
{
return new BuildResult(generateResult, false, new Exception("dotnet restore has failed"), null);
}
if (!ExecuteCommand(
$"build --framework {Framework} --configuration {Configuration} --output {OutputDirectory}",
generateResult.DirectoryPath,
logger))
{
// dotnet cli could have succesfully builded the program, but returned 1 as exit code because it had some warnings
// so we need to check whether the exe exists or not, if it does then it is OK
var executablePath = BuildExecutablePath(generateResult, benchmark);
if (File.Exists(executablePath))
{
return new BuildResult(generateResult, true, null, executablePath);
}
return new BuildResult(generateResult, false, new Exception("dotnet build has failed"), null);
}
return new BuildResult(generateResult, true, null, BuildExecutablePath(generateResult, benchmark));
}
示例3: Summary
private Summary(string title, HostEnvironmentInfo hostEnvironmentInfo, IConfig config, string resultsDirectoryPath, TimeSpan totalTime, ValidationError[] validationErrors, Benchmark[] benchmarks, BenchmarkReport[] reports)
: this(title, hostEnvironmentInfo, config, resultsDirectoryPath, totalTime, validationErrors)
{
Benchmarks = benchmarks;
Table = new SummaryTable(this);
Reports = reports ?? new BenchmarkReport[0];
}
示例4: Build
/// <summary>
/// generates project.lock.json that tells compiler where to take dlls and source from
/// and builds executable and copies all required dll's
/// </summary>
public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
{
if (!DotNetCliCommandExecutor.ExecuteCommand(
RestoreCommand,
generateResult.DirectoryPath,
logger,
DefaultTimeout))
{
return new BuildResult(generateResult, false, new Exception("dotnet restore has failed"), null);
}
if (!DotNetCliCommandExecutor.ExecuteCommand(
GetBuildCommand(TargetFrameworkMonikerProvider(benchmark.Job.Framework)),
generateResult.DirectoryPath,
logger,
DefaultTimeout))
{
// dotnet cli could have succesfully builded the program, but returned 1 as exit code because it had some warnings
// so we need to check whether the exe exists or not, if it does then it is OK
var executablePath = BuildExecutablePath(generateResult, benchmark);
if (File.Exists(executablePath))
{
return new BuildResult(generateResult, true, null, executablePath);
}
return new BuildResult(generateResult, false, new Exception("dotnet build has failed"), null);
}
return new BuildResult(generateResult, true, null, BuildExecutablePath(generateResult, benchmark));
}
示例5: CreateStartInfo
private ProcessStartInfo CreateStartInfo(Benchmark benchmark, string exeName, string args, string workingDirectory, IResolver resolver)
{
var start = new ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
WorkingDirectory = workingDirectory
};
var runtime = benchmark.Job.Env.HasValue(EnvMode.RuntimeCharacteristic)
? benchmark.Job.Env.Runtime
: RuntimeInformation.GetCurrentRuntime();
// TODO: use resolver
switch (runtime)
{
case Runtime.Clr:
case Runtime.Core:
start.FileName = exeName;
start.Arguments = args;
break;
case Runtime.Mono:
start.FileName = "mono";
start.Arguments = GetMonoArguments(benchmark.Job, exeName, args, resolver);
break;
default:
throw new NotSupportedException("Runtime = " + runtime);
}
return start;
}
示例6: CreateStartInfo
private ProcessStartInfo CreateStartInfo(Benchmark benchmark, string exeName, string args, string workingDirectory)
{
var start = new ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
WorkingDirectory = workingDirectory
};
var runtime = benchmark.Job.Runtime == Runtime.Host ? EnvironmentHelper.GetCurrentRuntime() : benchmark.Job.Runtime;
switch (runtime)
{
case Runtime.Clr:
case Runtime.Dnx:
case Runtime.Core:
start.FileName = exeName;
start.Arguments = args;
break;
case Runtime.Mono:
start.FileName = "mono";
start.Arguments = exeName + " " + args;
break;
default:
throw new NotSupportedException("Runtime = " + benchmark.Job.Runtime);
}
return start;
}
示例7: Build
/// <summary>
/// generates project.lock.json that tells compiler where to take dlls and source from
/// and builds executable and copies all required dll's
/// </summary>
public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark, IResolver resolver)
{
if (!DotNetCliCommandExecutor.ExecuteCommand(
RestoreCommand,
generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath,
logger,
DefaultTimeout))
{
return BuildResult.Failure(generateResult, new Exception("dotnet restore has failed"));
}
if (!DotNetCliCommandExecutor.ExecuteCommand(
GetBuildCommand(TargetFrameworkMoniker),
generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath,
logger,
DefaultTimeout))
{
// dotnet cli could have succesfully builded the program, but returned 1 as exit code because it had some warnings
// so we need to check whether the exe exists or not, if it does then it is OK
if (File.Exists(generateResult.ArtifactsPaths.ExecutablePath))
{
return BuildResult.Success(generateResult);
}
return BuildResult.Failure(generateResult);
}
return BuildResult.Success(generateResult);
}
示例8: Main
static void Main(string[] args)
{
MyConsole.WriteLine("Hello World");
const int threadCount = 4;
const int width = 1000;
const int height = 1000;
const int moleculaCount = 10000;
var time = TimeSpan.FromSeconds(0.01);
var random = new Random();
var forceCalculatingService = new ForceCalculatingService();
var moleculasUpdatingService = new MoleculasUpdatingService();
var factory = new ForceStategyFactory();
var moleculasA = new Molecula[moleculaCount];
var moleculasB = new Molecula[moleculaCount];
for (int i = 0; i < moleculaCount; i++)
{
int x = random.Next(width);
int y = random.Next(height);
var moleculaA = new Molecula(null);
var moleculaB = new Molecula(null);
moleculaA.Position = new Vector2(x, y);
moleculaB.Position = new Vector2(x, y);
moleculasA[i] = moleculaA;
moleculasB[i] = moleculaB;
}
var strategies = new BaseForceStrategy[]
{
factory.GetBasicForceStrategy(moleculasA, forceCalculatingService, moleculasUpdatingService),
factory.GetParallelForceStratagy(moleculasB, forceCalculatingService, moleculasUpdatingService,
threadCount)
};
foreach (var strategy in strategies)
{
strategy.Time = time;
strategy.Height = height;
strategy.Width = width;
}
do
{
var benchmark = new Benchmark<object>(strategies);
if (!benchmark.StartBenchmark().IsBechmarkSuccessful)
{
break;
}
MyConsole.WriteLine();
} while (true);
MyConsole.WriteLine("Tests finished!! Press enter");
MyConsole.ReadLine();
}
示例9: Put
// PUT api/benchmark/5
public HttpResponseMessage Put(int id, Benchmark viewModel)
{
viewModel.User = this.User.Identity.Name;
if (!ModelState.IsValid)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
}
if (id != viewModel.BenchmarkID)
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
db.Entry(viewModel).State = EntityState.Modified;
try
{
db.SaveChanges();
}
catch (DbUpdateConcurrencyException ex)
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
示例10: GetAllReferences
internal static IEnumerable<Assembly> GetAllReferences(Benchmark benchmark)
{
return benchmark.Target.Type.GetTypeInfo().Assembly
.GetReferencedAssemblies()
.Select(Assembly.Load)
.Concat(new[] { benchmark.Target.Type.GetTypeInfo().Assembly });
}
示例11: PutBenchmark
public async Task<IHttpActionResult> PutBenchmark(int id, Benchmark benchmark)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != benchmark.BenchmarkID)
{
return BadRequest();
}
db.Entry(benchmark).State = EntityState.Modified;
try
{
await db.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!BenchmarkExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return StatusCode(HttpStatusCode.NoContent);
}
示例12: CreateProjectDirectory
private GenerateResult CreateProjectDirectory(Benchmark benchmark, string rootArtifactsFolderPath, IConfig config)
{
var directoryPath = GetBinariesDirectoryPath(benchmark, rootArtifactsFolderPath, config);
bool exist = Directory.Exists(directoryPath);
Exception deleteException = null;
for (int attempt = 0; attempt < 3 && exist; attempt++)
{
if (attempt != 0)
Thread.Sleep(500); // Previous benchmark run didn't release some files
try
{
Directory.Delete(directoryPath, true);
exist = Directory.Exists(directoryPath);
}
catch (DirectoryNotFoundException)
{
exist = false;
break;
}
catch (Exception e)
{
// Can't delete the directory =(
deleteException = e;
}
}
if (exist)
return new GenerateResult(directoryPath, false, deleteException);
if (!Directory.Exists(directoryPath))
Directory.CreateDirectory(directoryPath);
return new GenerateResult(directoryPath, true, null);
}
示例13: Generate
internal static string Generate(Benchmark benchmark)
{
var provider = GetDeclarationsProvider(benchmark.Target);
string text = new SmartStringBuilder(ResourceHelper.LoadTemplate("BenchmarkProgram.txt")).
Replace("$OperationsPerInvoke$", provider.OperationsPerInvoke).
Replace("$TargetTypeNamespace$", provider.TargetTypeNamespace).
Replace("$TargetMethodReturnTypeNamespace$", provider.TargetMethodReturnTypeNamespace).
Replace("$TargetTypeName$", provider.TargetTypeName).
Replace("$TargetMethodDelegate$", provider.TargetMethodDelegate).
Replace("$TargetMethodDelegateType$", provider.TargetMethodDelegateType).
Replace("$IdleMethodDelegateType$", provider.IdleMethodDelegateType).
Replace("$IdleMethodReturnType$", provider.IdleMethodReturnType).
Replace("$SetupMethodName$", provider.SetupMethodName).
Replace("$CleanupMethodName$", provider.CleanupMethodName).
Replace("$IdleImplementation$", provider.IdleImplementation).
Replace("$HasReturnValue$", provider.HasReturnValue).
Replace("$AdditionalLogic$", benchmark.Target.AdditionalLogic).
Replace("$JobSetDefinition$", GetJobsSetDefinition(benchmark)).
Replace("$ParamsContent$", GetParamsContent(benchmark)).
Replace("$ExtraAttribute$", GetExtraAttributes(benchmark.Target)).
Replace("$EngineFactoryType$", GetEngineFactoryTypeName(benchmark)).
ToString();
text = Unroll(text, benchmark.Job.ResolveValue(RunMode.UnrollFactorCharacteristic, EnvResolver.Instance));
return text;
}
示例14: GetValue
public string GetValue(Summary summary, Benchmark benchmark)
{
var baselineBenchmark = summary.Benchmarks.
Where(b => b.Job.GetFullInfo() == benchmark.Job.GetFullInfo()).
Where(b => b.Parameters.FullInfo == benchmark.Parameters.FullInfo).
FirstOrDefault(b => b.Target.Baseline);
if (baselineBenchmark == null)
return "?";
var baselineMedian = summary.Reports[baselineBenchmark].ResultStatistics.Median;
var currentMedian = summary.Reports[benchmark].ResultStatistics.Median;
switch (Kind)
{
case DiffKind.Delta:
if (benchmark.Target.Baseline)
return "Baseline";
var diff = (currentMedian - baselineMedian)/baselineMedian*100.0;
return diff.ToStr("0.0") + "%";
case DiffKind.Scaled:
var scale = currentMedian/baselineMedian;
return scale.ToStr("0.00");
default:
return "?";
}
}
示例15: GetValue
public string GetValue(Summary summary, Benchmark benchmark)
{
var ranks = RankHelper.GetRanks(summary.Reports.Select(r => r.ResultStatistics).ToArray());
int index = Array.IndexOf(summary.Reports.Select(r => r.Benchmark).ToArray(), benchmark);
int rank = ranks[index];
return system.ToPresentation(rank);
}