inline.cpp

来自「《C/C++程序员实用大全》配套代码,适用初学C++的人员。」· C++ 代码 · 共 55 行

CPP
55
字号
#include <iostream.h>
#include <time.h>

inline void swap_inline(int *a, int *b, int *c, int *d)
 {
   int temp;

   temp = *a;
   *a = *b;
   *b = temp;

   temp = *c;
   *c = *d;
   *d = temp;
 }

void swap_call(int *a, int *b, int *c, int *d)
 {
   int temp;

   temp = *a;
   *a = *b;
   *b = temp;

   temp = *c;
   *c = *d;
   *d = temp;
 }


void main(void)
 {
   clock_t start, stop;
   long int i;
   int a = 1, b = 2, c = 3, d = 4;

   start = clock();
   for (i = 0; i < 300000L; i++)
     swap_inline(&a, &b, &c, &d);
   stop = clock();
   cout << "Time for inline: " << stop - start;
   
   start = clock();
   for (i = 0; i < 300000L; i++)
     swap_call(&a, &b, &c, &d);
   stop = clock();

   cout << "\nTime for called function: " << stop - start;
 }

   



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?