We are working on two different libraries which tends to perform the same work. I have been assigned to check which library performs the same work faster with given set of inputs. there are multiple test cases to determine this and i want to check how much time(in miliseconds) is taken by the library to perform the task.
Following is the outline of the code.
// preparation of input parameters
// Get the timestamp
// Calling the desired library with the set of input parameters
// again get the timestamp
// Process the output received from the library
// get a diff between timestamp and write it into a file.
I am supposed to do it in C#, and on reading up some provided docs and some online search i came up with following code which can be used to measure the time taken(in miliseconds)
int s1 = DateTime.Now.Millisecond;
int e1 = DateTime.Now.Millisecond;
int f1 = e1 - s1;
FileStream fs = new FileStream("Time_Diff.txt", FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
string str = Convert.ToString(f1);
sw.WriteLine(str);
sw.WriteLine(e1 + " " + s1);
sw.Flush();
sw.Close();
I just wanted to know that I am going in correct direction. Also if anybody can suggest me another way of doing the same thing?
another thing i wanted to know is what are other practical approches I can use to make sure that the library we are choosing will give the best performance?
another small request. Can somebody please let me know how to implement stopwatch(or any other similar way to get the timestamp)do the same thing in C++?
Thanks, Azeem