PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/base/Applications/Benchmarks/SharedHeap/SharedHeapBench.cs

#
C# | 106 lines | 63 code | 22 blank | 21 comment | 1 complexity | 0659854afdf178ff89f5690529c4be29 MD5 | raw file
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Research Singularity
  4. //
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. //
  7. // Note: Singularity micro-benchmark program.
  8. //
  9. using Microsoft.Singularity;
  10. using Microsoft.Singularity.V1.Services;
  11. using Microsoft.Singularity.V1.Threads;
  12. using System;
  13. using System.Runtime.CompilerServices;
  14. using System.Diagnostics;
  15. using System.Threading;
  16. using Microsoft.Singularity.Channels;
  17. using Microsoft.Contracts;
  18. using Microsoft.SingSharp.Reflection;
  19. using Microsoft.Singularity.Applications;
  20. using Microsoft.Singularity.Io;
  21. using Microsoft.Singularity.Configuration;
  22. [assembly: Transform(typeof(ApplicationResourceTransform))]
  23. namespace Microsoft.Singularity.Applications
  24. {
  25. [ConsoleCategory(HelpMessage="Show attributes associated with a file", DefaultAction=true)]
  26. internal class Parameters {
  27. [InputEndpoint("data")]
  28. public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
  29. [OutputEndpoint("data")]
  30. public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
  31. [BoolParameter( "q", Default=false, HelpMessage="Quiet Mode.")]
  32. internal bool quietMode;
  33. [LongParameter( "r", Default=1, HelpMessage="Repetition count.")]
  34. internal long repetitions;
  35. reflective internal Parameters();
  36. internal int AppMain() {
  37. return SharedHeapBench.AppMain(this);
  38. }
  39. }
  40. //
  41. // The goal of this test is to time how long it takes to
  42. // create a process.
  43. //
  44. public class SharedHeapBench
  45. {
  46. internal static int AppMain(Parameters! config)
  47. {
  48. int iterations = 10000;
  49. Console.Write("\nTime alloc/free ops in the shared heap\n\n");
  50. TimeCycle(10, iterations);
  51. Thread.Sleep(1000);
  52. TimeCycle(100, iterations);
  53. Thread.Sleep(1000);
  54. TimeCycle(1000, iterations);
  55. Thread.Sleep(1000);
  56. TimeCycle(10000, iterations);
  57. return 0;
  58. }
  59. //
  60. // The goal of this routine is to focus on the shared heap operations
  61. // themselves. So we allocate and then free the same amount of memory
  62. // repeatedly, which (for small region allocations) won't cause us to
  63. // go to the Page manager in steady state.
  64. //
  65. public static void TimeCycle(int bytes, int iterations)
  66. {
  67. ulong before = Processor.CycleCount;
  68. for (int loop = 0; loop < iterations; loop++) {
  69. SharedHeapService.Allocation *mem;
  70. mem = (SharedHeapService.Allocation *)
  71. SharedHeapService.Allocate((UIntPtr)bytes, typeof(byte).GetSystemType(), 0);
  72. SharedHeapService.Free(mem);
  73. }
  74. ulong after = Processor.CycleCount;
  75. //
  76. // Tell the world.
  77. //
  78. Console.Write("\nTested {0} alloc/free iterations of {1} bytes\n",
  79. iterations, bytes);
  80. Console.Write("Total cycles: {0}\n", after - before);
  81. Console.Write("\n\n");
  82. }
  83. }
  84. }