Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- namespace SimpleBoolSpeedTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- while (true)
- {
- //Extremely simplistic if (boolean) speed test.
- long testLength = 100000000;
- bool[] data = new bool[testLength];
- var rand = new Random();
- for (int i = 0; i < data.Length; i++)
- data[i] = (rand.Next(2) > 0);
- var sw = new Stopwatch();
- long count = 0;
- sw.Start();
- for (int i = 0; i < data.Length; i++)
- if (data[i]) count++;
- sw.Stop();
- Console.WriteLine("Simple 'if (boolean)' speed test:" + count.ToString());
- Console.WriteLine(testLength.ToString("N0") + " iterations in " + sw.ElapsedMilliseconds.ToString("N0") + "ms");
- Console.WriteLine((testLength / sw.ElapsedMilliseconds).ToString("N0") + " its/ms");
- Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement