diff options
author | David Wrighton <davidwr@microsoft.com> | 2017-09-13 14:50:39 -0700 |
---|---|---|
committer | David Wrighton <davidwr@microsoft.com> | 2017-09-13 14:50:39 -0700 |
commit | d68f0916d0a2bf3787bc85261ef4a4f1f27f1f24 (patch) | |
tree | 6c21ac239ae268096f20d98a8db16a4b80394fd9 /tests/src/GC/Performance/Tests/LOHSmooth.cs | |
parent | 96fa98525e0d64459148228cde5211c475b0c25c (diff) | |
parent | e866d072042f4ad9e0811aa36e338dac781c09a5 (diff) | |
download | coreclr-d68f0916d0a2bf3787bc85261ef4a4f1f27f1f24.tar.gz coreclr-d68f0916d0a2bf3787bc85261ef4a4f1f27f1f24.tar.bz2 coreclr-d68f0916d0a2bf3787bc85261ef4a4f1f27f1f24.zip |
Merge branch 'master' into update_from_master
Diffstat (limited to 'tests/src/GC/Performance/Tests/LOHSmooth.cs')
-rw-r--r-- | tests/src/GC/Performance/Tests/LOHSmooth.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/src/GC/Performance/Tests/LOHSmooth.cs b/tests/src/GC/Performance/Tests/LOHSmooth.cs new file mode 100644 index 0000000000..e421394d53 --- /dev/null +++ b/tests/src/GC/Performance/Tests/LOHSmooth.cs @@ -0,0 +1,64 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Threading; +using System.Diagnostics; + +public class VSTSTest +{ + static int _threadCount = 16; + static int _minSize = 200 * 1024; + static int _maxSize = 250 * 1024; + static int _holdSize = 100; + static int _maxCount = 100; + static int _count = 0; + static bool _done = false; + static long _maxPrivate = 0; + static object lockObject = new Object(); + + // each worker will hold *in the worst case scenario* 100 * 250k * 2 = 50MB + // all 16 threads will hold in the worst case scenario 800MB + static void Worker(object ctx) + { + string[] s = new string[_holdSize]; + Random rnd = new Random(); + for (int i = 0; i < _holdSize; i++) + { + Thread.Sleep(rnd.Next(50, 100)); + s[i] = new string('x', rnd.Next(_minSize, _maxSize)); + + long _private = Process.GetCurrentProcess().PrivateMemorySize64; + + lock (lockObject) + { + if (_private > _maxPrivate) + _maxPrivate = _private; + } + } + + if (_count++ >= _maxCount) + _done = true; + + if (!_done) + ThreadPool.QueueUserWorkItem(Worker); + } + + static public void Allocate() + { + for (int i = 0; i < _threadCount; i++) + { + ThreadPool.QueueUserWorkItem(Worker); + } + } + + public static void Main(string[] args) + { + Allocate(); + while (!_done) + { + Thread.Sleep(0); + } + } +} |