Program.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.CompilerServices;
  4. using XUnity.RuntimeHooker.Core;
  5. namespace XUnity.RuntimeHooker.Benchmark
  6. {
  7. class Program
  8. {
  9. static void Main( string[] args )
  10. {
  11. int a = 12;
  12. int b = 23;
  13. MyMethod( a, b );
  14. var myMethod = typeof( Program ).GetMethod( "MyMethod" );
  15. var myHook = typeof( Program ).GetMethod( "MyHook" );
  16. int iterations = 10000;
  17. var sw = Stopwatch.StartNew();
  18. for( int i = 0 ; i < iterations ; i++ )
  19. {
  20. MyMethod( a, b );
  21. }
  22. Console.WriteLine( sw.ElapsedMilliseconds );
  23. RuntimeMethodPatcher.Patch( myMethod, new HookMethod( myHook ), null );
  24. MyMethod( a, b );
  25. sw.Reset();
  26. sw.Start();
  27. for( int i = 0 ; i < iterations ; i++ )
  28. {
  29. MyMethod( a, b );
  30. }
  31. Console.WriteLine( sw.ElapsedMilliseconds );
  32. }
  33. [MethodImpl( MethodImplOptions.NoInlining )]
  34. public static void MyMethod( int a, int b )
  35. {
  36. }
  37. public static void MyHook( int b, int a )
  38. {
  39. }
  40. }
  41. }