Resource Waster
Wastes system resources and processing powerunknown
csharp
3 years ago
2.5 kB
39
Indexable
using System.Data;
using System.Security.Cryptography;
while (true)
{
try
{
Parallel.For(0, 10, new ParallelOptions { MaxDegreeOfParallelism = 10 }, ResourceWaster.WasteResources);
}
catch { throw; }
}
static class ResourceWaster
{
private static List<string> _OurStrings = new();
private static List<DataTable> _OurData = new();
private static List<RandomNumberGenerator> _OurRandoms = new();
private static List<Rfc2898DeriveBytes> _OurHashers = new();
private static List<byte[]> _OurBytes = new();
private static List<object[]> _OurObjects = new();
public static void WasteResources(int index)
{
var tableName = "";
tableName += "T";
tableName += "a";
tableName += "b";
tableName += "l";
tableName += "e";
tableName += " ";
tableName += index.ToString();
_OurStrings.Add(tableName);
//Datatable to use memory
var dataTable = new DataTable($"{tableName}");
_OurData.Add(dataTable);
for (int i = 0; i < 10; i++)
{
string colName = "Col" + $"{i}";
_OurStrings.Add(colName);
dataTable.Columns.Add(new DataColumn { ColumnName = colName });
}
for (int i = 0; i < 100000; i++)
{
var text = i.ToString();
_OurStrings.Add(text);
var rng = RandomNumberGenerator.Create();
_OurRandoms.Add(rng);
byte[] bytes = new byte[32];
_OurBytes.Add(bytes);
rng.GetBytes(bytes);
//Hashing to use CPU
var pbkdf2 = new Rfc2898DeriveBytes(text, bytes, 50, HashAlgorithmName.SHA512);
_OurHashers.Add(pbkdf2);
byte[] hash = new byte[64];
_OurBytes.Add(hash);
object[] rowValues = new object[10];
_OurObjects.Add(rowValues);
for (int j = 0; j < 10; j++)
{
hash = pbkdf2.GetBytes(64);
rowValues[j] = $"Col" + j.ToString() + " Data" + " " + Convert.ToBase64String(hash);
}
dataTable.Rows.Add(rowValues);
//Suppress the garbage collector from stealing our resources
GC.SuppressFinalize(rowValues);
GC.SuppressFinalize(rng);
GC.SuppressFinalize(pbkdf2);
}
GC.SuppressFinalize(tableName);
GC.SuppressFinalize(dataTable);
}
}Editor is loading...