Instantly share code, notes, and snippets.

Embed
What would you like to do?
make and operate on lots of classes and structs
using System;
using System.Collections.Generic;
using ClassOrStruct;
namespace Runner
{
class Program
{
private static readonly Random Random = new Random();
private const int Capacity = 25000000;
static void Main(string[] args)
{
AddObjectsTogether();
AddStructsTogether();
}
private static void AddStructsTogether()
{
var endValues = new List<ValueStruct>(Capacity);
foreach (var value in CreateABunchOfStructs())
{
endValues.Add(value + MakeRandomValueStruct());
}
}
private static void AddObjectsTogether()
{
var endValues = new List<ValueClass>(Capacity);
foreach (var value in CreateABunchOfObjects())
{
endValues.Add(value + MakeRandomValueClass());
}
}
private static ValueStruct MakeRandomValueStruct()
{
return new ValueStruct(Random.NextDouble(), Random.NextDouble(), Random.NextDouble(), Random.NextDouble());
}
private static ValueClass MakeRandomValueClass()
{
return new ValueClass(Random.NextDouble(), Random.NextDouble(), Random.NextDouble(), Random.NextDouble());
}
private static IEnumerable<ValueStruct> CreateABunchOfStructs()
{
for (var i = 0; i < Capacity; i++)
{
yield return MakeRandomValueStruct();
}
}
private static IEnumerable<ValueClass> CreateABunchOfObjects()
{
for (var i = 0; i < Capacity; i++)
{
yield return MakeRandomValueClass();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment