This article summarizes the time used for testing a program using the benchmark method, or the performance of data structures and algorithms in the program.
The Code is as follows:
Namespace timingtestdemo1 {// custom timing class public class timing {// Private field timespan duration; // constructor, initialization field public timing () {duration = new timespan (0);} // start timing public void starttime () {GC. collect (); // forcibly execute garbage collection GC. waitforpendingfinalizers (); // suspend the current thread until the thread processing the terminator queue clears the queue} // end time public void stoptime () {duration = process. getcurrentprocess (). totalprocessortime;} public timespan result () {return duration ;}} class program {static void main (string [] ARGs) {// declaration and initialization array int [] Nums = new int [100000]; buildarray (Nums); timing tobj = new timing (); // start tobj. starttime (); displaynums (Nums); // end of time tobj. stoptime (); console. writeline ("\ nexpend time:" + tobj. result (). totalseconds + "S"); console. readkey ();} Private Static void buildarray (INT [] ARR) {for (INT I = 0; I <= arr. length-1; I ++) {arr [I] = I ;}} Private Static void displaynums (INT [] ARR) {for (INT I = 0; I <= arr. getupperbound (0); I ++) {console. write (ARR [I] + "");}}}}
The program output result is:
The above is my summary of the Program Performance Testing class, which can be used in subsequent data structures and algorithms.