2
0

StringBuilderBenchmark.cs 642 B

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