Skip to content

Instantly share code, notes, and snippets.

@SidShetye
Created January 29, 2013 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SidShetye/4661615 to your computer and use it in GitHub Desktop.
Save SidShetye/4661615 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
Application app = new Application();
app.Run();
}
}
public class Application
{
public void Run()
{
int samplesToCollect = 100;
string executable = "openssl";
List<string> allArgs = new List<string>();
allArgs.Add("q"); // just quit - to find invocation overhead
allArgs.Add("aes-256-gcm -in 10M-plain.bin -out /dev/null -k password.txt");
allArgs.Add("aes-256-cbc -in 10M-plain.bin -out /dev/null -k password.txt");
foreach (string arg in allArgs)
{
double totalMs = 0;
for (int i = 0; i < samplesToCollect; i++)
{
totalMs += RunCommandGetTime(executable, arg).TotalMilliseconds;
}
Console.WriteLine("'{0} {1}' took {2} milliseconds (avg)", executable, arg, totalMs / samplesToCollect); //avg
}
Console.ReadLine();
}
private TimeSpan RunCommandGetTime(string exe, string args)
{
Stopwatch sw = new Stopwatch();
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = exe;
myProcess.StartInfo.Arguments = args;
myProcess.StartInfo.CreateNoWindow = false; // true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardError = true;
sw.Start();
myProcess.Start();
myProcess.WaitForExit();
sw.Stop();
return sw.Elapsed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment