INLINE.CPP
Upload User: dq031136
Upload Date: 2022-08-08
Package Size: 802k
Code Size: 1k
Development Platform:

C++ Builder

  1. #include <iostream.h>
  2. #include <time.h>
  3. inline void swap_inline(int *a, int *b, int *c, int *d)
  4.  {
  5.    int temp;
  6.    temp = *a;
  7.    *a = *b;
  8.    *b = temp;
  9.    temp = *c;
  10.    *c = *d;
  11.    *d = temp;
  12.  }
  13. void swap_call(int *a, int *b, int *c, int *d)
  14.  {
  15.    int temp;
  16.    temp = *a;
  17.    *a = *b;
  18.    *b = temp;
  19.    temp = *c;
  20.    *c = *d;
  21.    *d = temp;
  22.  }
  23. void main(void)
  24.  {
  25.    clock_t start, stop;
  26.    long int i;
  27.    int a = 1, b = 2, c = 3, d = 4;
  28.    start = clock();
  29.    for (i = 0; i < 300000L; i++)
  30.      swap_inline(&a, &b, &c, &d);
  31.    stop = clock();
  32.    cout << "Time for inline: " << stop - start;
  33.    
  34.    start = clock();
  35.    for (i = 0; i < 300000L; i++)
  36.      swap_call(&a, &b, &c, &d);
  37.    stop = clock();
  38.    cout << "nTime for called function: " << stop - start;
  39.  }
  40.