Review data structures and algorithms (1) Build your own time test class

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.