summaryrefslogtreecommitdiff
path: root/tests/src/GC/Performance/Tests/EEGC.cs
blob: 3bbfe9d8a05cd5d9418922260d6040a1f8c13bc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace EEGC
{
    using System;
    using System.Threading;

    public class EEGC
    {
        internal static int kStretchTreeDepth;
        internal static int kLongLivedTreeDepth;
        internal static int kShortLivedTreeDepth;
        const int NUM_ITERATIONS = 200;

        internal static void Populate(int iDepth, Node thisNode)
        {
            if (iDepth <= 0)
                return;

            else
            {
                iDepth--;
                thisNode.left = new Node();
                thisNode.right = new Node();
                Populate(iDepth, thisNode.left);
                Populate(iDepth, thisNode.right);
            }
        }

        public static void Main(string[] p_args)
        {
            Node root;
            Node longLivedTree;
            Node tempTree;
            Thread sleepThread;

            kStretchTreeDepth = 19;     // about 24MB
            kLongLivedTreeDepth = 18;   // about 12MB
            kShortLivedTreeDepth = 13;  // about 0.4MB

            tempTree = new Node();
            Populate(kStretchTreeDepth, tempTree);
            tempTree = null;

            longLivedTree = new Node();
            Populate(kLongLivedTreeDepth, longLivedTree);

            SleepThread sThread;
            sThread = new SleepThread(100);
            sleepThread = new Thread(new ThreadStart(SleepThread.ThreadStart));

            sleepThread.Start();

            for (long i = 0; i < NUM_ITERATIONS; i++)
            {
                root = new Node();
                Populate(kShortLivedTreeDepth, root);
            }

            root = longLivedTree;

            SleepThread.shouldContinue = false;
            sleepThread.Join(500);
        }
    }
}