StringBuilderBenchmark.cs 752 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using BenchmarkDotNet.Attributes;
  2. namespace Jint.Benchmark
  3. {
  4. [MemoryDiagnoser]
  5. public class StringBuilderBenchmark
  6. {
  7. private const string script = @"
  8. var x = 'some string';
  9. ";
  10. private Engine engine;
  11. [GlobalSetup]
  12. public void Setup()
  13. {
  14. engine = new Engine();
  15. engine.Execute(script);
  16. }
  17. [Benchmark]
  18. public void One()
  19. {
  20. engine.Execute("`hello ${x}`");
  21. }
  22. [Benchmark]
  23. public void Two()
  24. {
  25. engine.Execute("`hello ${x}, hello ${x}`");
  26. }
  27. [Benchmark]
  28. public void Three()
  29. {
  30. engine.Execute("`hello ${x}, hello ${x}, hello ${x}`");
  31. }
  32. }
  33. }