get runtime | struct definition

1. How to test the running time of the program

GetTickCount()
function Function: GetTickCount() is to get the time interval after the system is started. By entering the function start timing and exiting the function end timing, the execution time (unit ms) of the function can be determined.
This time is not the real execution time of the function or algorithm, because it is impossible for the function and algorithm thread to occupy the CPU all the time. It is the same for all functions that judge the execution time, but it is basically accurate. Note: GetTickCount() has limited accuracy and is related to the CPU.

include<windows.h>

int t1 = long t1 = GetTickCount();
    //...测试代码
int t1 = long t2 = GetTickCount();
cout << "运行时间:"<<(t2-t1) << endl;

2. Structure definition: distinguish the usage of struct and typedef struct

The purpose of typedef: In the C/C++ language, typedef is often used to define an alias for an identifier and a keyword

2.1 To define a structure type in C, use typedef:

typedef struct Student
{
int a;
}Stu; //这里的Stu实际上就是struct Student的别名。

//于是在声明变量的时候就可①:Stu stu1;
//②如果没有typedef就必须用struct Student stu1;来声明

2.2 If you use typedef in C++, it will make a difference:

typedef struct Student2 
{ 
int a; 
}stu2;//stu2是一个结构体类型 
//因此 stu2则必须先 stu2 s2;  然后 s2.a=10;

To sum up, I decided not to use typedef and directly use C++'s struct definition

struct Student 
{ 
int a; 
}stu1;//stu1是一个变量,使用时可以直接访问stu1.a

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324774990&siteId=291194637