当前位置: 首页>>代码示例>>C#>>正文


C# Benchmark类代码示例

本文整理汇总了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);
 }
开发者ID:IrwinDong,项目名称:BenchmarkDotNet,代码行数:7,代码来源:BenchmarkClassicFlow.cs

示例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));
        }
开发者ID:adamsitnik,项目名称:BenchmarkDotNet,代码行数:29,代码来源:DnxBuilder.cs

示例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];
 }
开发者ID:alexandrnikitin,项目名称:BenchmarkDotNet,代码行数:7,代码来源:Summary.cs

示例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));
        }
开发者ID:yaozd,项目名称:BenchmarkDotNet,代码行数:34,代码来源:DotNetCliBuilder.cs

示例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;
 }
开发者ID:alexandrnikitin,项目名称:BenchmarkDotNet,代码行数:30,代码来源:Executor.cs

示例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;
 }
开发者ID:omariom,项目名称:BenchmarkDotNet,代码行数:28,代码来源:ClassicExecutor.cs

示例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);
        }
开发者ID:alexandrnikitin,项目名称:BenchmarkDotNet,代码行数:33,代码来源:DotNetCliBuilder.cs

示例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();
        }
开发者ID:SButterfly,项目名称:ParallelProgrammingCourse,代码行数:60,代码来源:Program.cs

示例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);
        }
开发者ID:EuropeanUniversityAssociation,项目名称:FRINDOC,代码行数:28,代码来源:BenchmarkController.cs

示例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 });
 }
开发者ID:yuleyule66,项目名称:BenchmarkDotNet,代码行数:7,代码来源:RoslynGenerator.cs

示例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);
        }
开发者ID:goonit,项目名称:Log_My_WOD_API,代码行数:32,代码来源:BenchmarksController.cs

示例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);
 }
开发者ID:redknightlois,项目名称:BenchmarkDotNet,代码行数:31,代码来源:GeneratorBase.cs

示例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;
        }
开发者ID:alexandrnikitin,项目名称:BenchmarkDotNet,代码行数:28,代码来源:CodeGenerator.cs

示例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 "?";
            }
        }
开发者ID:omariom,项目名称:BenchmarkDotNet,代码行数:26,代码来源:BaselineDiffColumn.cs

示例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);
 }
开发者ID:alexandrnikitin,项目名称:BenchmarkDotNet,代码行数:7,代码来源:RankColumn.cs


注:本文中的Benchmark类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。