Merge pull request #1063 from esdrubal/bug18482
[mono.git] / mono / tests / gc-graystack-stress.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Diagnostics;
4
5 class Program {
6         
7         class Node {
8                 Node child;
9                 Node sibling;
10
11                 public Node (int depth) : this (depth, null) {}
12
13                 public Node (int depth, Node sibling) {
14                         if (depth > 0)
15                                 this.child = new Node (depth - 1);
16
17                         this.sibling = sibling;
18                 }
19
20                 public override String ToString () {
21                         return String.Format ("Node[child={0},sibling={1}]", this.child, this.sibling);
22                 }
23         }
24         
25         /**
26          * Usage : width [depth [collections]]
27          *  - width : trigger the overflow
28          *  - depth : modify the cost difference of the overflow
29          *  - collections : # of collections to perform
30          */
31         public static void Main (String[] args) {
32                 int width = 125;
33                 if (args.Length > 0)
34                         width = Math.Max (width, Int32.Parse (args [0]));
35
36                 int depth = 10000;
37                 if (args.Length > 1)
38                         depth = Math.Max (depth, Int32.Parse (args [1]));
39
40                 int collections = 100;
41                 if (args.Length > 2)
42                         collections = Math.Max (collections, Int32.Parse (args [2]));
43
44                 Node sibling = null;
45
46                 for (int i = 0; i < width; i++) {
47                         sibling = new Node(depth, sibling);
48                         if (i > 0 && i % 10 == 0)
49                                 Console.Write ("+");
50                 }
51
52                 for (int i = 0; i < collections; i++) {
53                         GC.Collect();
54                         if (i > 0 && i % 10 == 0)
55                                 Console.Write (".");
56                 }
57                 Console.WriteLine ();
58         }
59 }