Advertisement
Guest User

Untitled

a guest
Apr 26th, 2021
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using BenchmarkDotNet.Attributes;
  2. using BenchmarkDotNet.Running;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Reflection;
  7. using Microsoft.CodeAnalysis.CSharp.Scripting;
  8. using Microsoft.CodeAnalysis.Scripting;
  9. using System.Threading.Tasks;
  10.  
  11. namespace Benchmark
  12. {
  13.     public class Program
  14.     {
  15.         private ScriptOptions options = ScriptOptions.Default.WithOptimizationLevel(Microsoft.CodeAnalysis.OptimizationLevel.Release);
  16.         private ScriptState state;
  17.         private string code = "";
  18.         private Script script;
  19.  
  20.         [GlobalSetup]
  21.         public void Setup()
  22.         {
  23.             state = CSharpScript.RunAsync("int y = 0;", options).Result;
  24.             script = CSharpScript.Create("1+1", options);
  25.             script.Compile();
  26.         }
  27.        
  28.         [Benchmark]
  29.         public async Task FirstRun()
  30.         {
  31.             await CSharpScript.RunAsync("int x = 1 + 1;", options);
  32.         }
  33.  
  34.         [Benchmark]
  35.         public async Task StateContinue()
  36.         {
  37.             state = await state.ContinueWithAsync("y += 1;", options);
  38.         }
  39.         [Benchmark]
  40.         public async Task Precompiled()
  41.         {
  42.             await script.RunAsync();
  43.         }
  44.  
  45.         static void Main(string[] args)
  46.         {
  47.             var summary = BenchmarkRunner.Run<Program>();
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement