Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Linq;
- namespace CodeGolf
- {
- class Program
- {
- static byte[] program = { 0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x01,0x00,0x00,0x00,0x00,
- 0x00,0x02,0x00,0x00,0x00,0x00,
- 0x02,0x01,
- 0x06,0x01,0x02,
- 0x02,0x02,
- 0x00,0x02,0x00,0x00,0x00,0x03,
- 0x07,0x01,0x02,
- 0x03,0x02,
- 0x04,0x00,0x01,
- 0x03,0x01,
- 0x02,0x02,
- 0x00,0x02,0x00,0x00,0x00,0x01,
- 0x04,0x01,0x02,
- 0x03,0x02,
- 0x02,0x02,
- 0x00,0x02,0x00,0x00,0x27,0x10,
- 0x09,0x01,0x02,
- 0x03,0x02,
- 0x0a,0x00,0x00,0x00,0x05,
- 0x00,0x01,0x00,0x00,0x00,0x01,
- 0x04,0x02,0x01,
- 0x00,0x01,0x00,0x00,0x27,0x10,
- 0x09,0x02,0x01,
- 0x00,0x01,0x00,0x00,0x00,0x00,
- 0x0a,0x00,0x00,0x00,0x03};
- static void Main(string[] args)
- {
- if (args.Length < 2) {
- Console.WriteLine("Arguments invalid:\nArgument 1 is the filename of the program or interpreter.\n Argument 2 is the collection of arguments to be passed to the program or interpreter.");
- }
- long[] times = new long[15];
- for (int i = 0; i < times.Length; i++)
- {
- System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
- string processOutput = "";
- var prc = new Process();
- prc.StartInfo.FileName = args[0];
- prc.StartInfo.Arguments = args[1];
- prc.StartInfo.RedirectStandardOutput = true;
- prc.StartInfo.RedirectStandardError = true;
- prc.EnableRaisingEvents = true;
- prc.StartInfo.CreateNoWindow = true;
- prc.StartInfo.UseShellExecute = false;
- prc.OutputDataReceived += (sender, eventArgs) =>
- {
- processOutput += eventArgs.Data + '\n';
- };
- prc.Start();
- prc.StandardInput.Write(program); //Pass the info over standardinput
- prc.WaitForExit();
- if (processOutput != "R0 1168066930\nR1 0\nR2 10000")
- {
- Console.WriteLine("Invalid output");
- Console.Read();
- return;
- }
- else
- {
- sw.Stop();
- times[i] = sw.ElapsedMilliseconds;
- Console.WriteLine("Test " + i + ": " + times[i].ToString("N0") + " ms");
- }
- }
- Console.WriteLine("Average time: " + times.Average().ToString("N2") + " ms");
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement