using System.Diagnostics;
public static void Main()
Stopwatch sw = new Stopwatch();
bool[] allFalse = new bool[iterations];
bool[] startTrue = new bool[iterations];
bool[] endTrue = new bool[iterations];
endTrue[iterations - 101] = true;
endTrue[iterations - 10001] = true;
bool[] multipleTrue = new bool[iterations];
multipleTrue[100] = true;
multipleTrue[10000] = true;
multipleTrue[iterations - 101] = true;
multipleTrue[iterations - 10001] = true;
multipleTrue[iterations / 2 - 1000] = true;
multipleTrue[iterations / 2 + 1000] = true;
StringBuilder sb = new StringBuilder();
sb.AppendLine($"Testing arrays with {iterations} elements");
TestArray(allFalse, "allFalse", sb, sw);
TestArray(startTrue, "startTrue", sb, sw);
TestArray(endTrue, "endTrue", sb, sw);
TestArray(multipleTrue, "multipleTrue", sb, sw);
Console.WriteLine(sb.ToString());
private static void LogAction(StringBuilder sb, Stopwatch sw, string actionName){
sb.AppendLine($"{actionName} took {sw.ElapsedMilliseconds} ms and {sw.ElapsedTicks} ticks");
private static void TestArray(bool[] array, string arrayName, StringBuilder sb, Stopwatch sw){
if (Array.IndexOf(array, true) == -1){
LogAction(sb, sw, $"{arrayName} with indexOf");
bool allElementsFalse = true;
for (int i = 0; i < array.Length; i++){
allElementsFalse = false;
LogAction(sb, sw, $"{arrayName} with custom loop and break");
var selectResult = (from item in array where item == true select item);
LogAction(sb, sw, $"{arrayName} with Linq select query");
if (array.Any(x => x == true)){
LogAction(sb, sw, $"{arrayName} with Linq select query");
if (array.All(x => x == false)){
LogAction(sb, sw, $"{arrayName} with Linq All");