www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/06/04/08:49:00

From: Alex Vinokur <alexvn AT bigfoot DOT com>
Newsgroups: comp.os.msdos.djgpp,comp.lang.c++
Subject: Optimization and operator&&
Date: Tue, 04 Jun 2002 14:44:51 +0200
Lines: 384
Message-ID: <3CFCB642.252CFFF7@bigfoot.com>
NNTP-Posting-Host: gateway.scopus.net (62.90.123.5)
Mime-Version: 1.0
X-Trace: fu-berlin.de 1023190976 34530432 62.90.123.5 (16 [79865])
X-Mailer: Mozilla 4.7 [en] (Win98; I)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

###############
Windows98
gcc/gpp 2.95.3
###############


A program below measures performance (time) :
  * of operator&& and operator+
  * with automatic and static unsigned int
  * with optimizations : No optimization, O1, O2, O3

We can see that Optimization causes
  an increase in elapsed time for operator&& .
Any explanation?

P.S Elapsed time of operator+ decreases.

Thanks in advance.


|| ###### C++ code : BEGIN ######
// File main.c

#include <time.h>
#include <utime.h>
#include <iostream>

static unsigned int static_uint;

int main ()
{
uclock_t start_time;
uclock_t end_time;
#define  THE_VALUE  52
#define  TOTAL_TESTS  10
#define  TOTAL_ITERATIONS 1000
int  t;
int  i;
unsigned int automatic_uint;

  cout << "--- static uint with OR ---" << endl;
  for (t = 0; t < TOTAL_TESTS; t++)
  {
    static_uint = 123;
    start_time = uclock();
    for (i = 0; i < TOTAL_ITERATIONS; i++)
    {
      static_uint = static_uint && THE_VALUE;
    }
    end_time = uclock();
    cout << "static, OR [" << (t + 1) << "] Total time : " << (end_time
- start_time) << endl;
  }

  cout << static_uint << endl;

  cout << endl;
  cout << "--- automatic uint with OR ---" << endl;
  for (t = 0; t < TOTAL_TESTS; t++)
  {
    automatic_uint = 123;
    start_time = uclock();
    for (i = 0; i < TOTAL_ITERATIONS; i++)
    {
      automatic_uint = automatic_uint && THE_VALUE;
    }
    end_time = uclock();
    cout << "automatic, OR [" << (t + 1) << "] Total time : " <<
(end_time - start_time) << endl;
  }
  cout << automatic_uint << endl;


  cout << endl;
  cout << endl;
  cout << "--- static uint with PLUS ---" << endl;
  for (t = 0; t < TOTAL_TESTS; t++)
  {
    static_uint = 123;
    start_time = uclock();
    for (i = 0; i < TOTAL_ITERATIONS; i++)
    {
      static_uint = static_uint + THE_VALUE;
    }
    end_time = uclock();
    cout << "static, PLUS [" << (t + 1) << "] Total time : " <<
(end_time - start_time) << endl;
  }
  cout << static_uint << endl;

  cout << endl;
  cout << "--- automatic uint with PLUS ---" << endl;
  for (t = 0; t < TOTAL_TESTS; t++)
  {
    automatic_uint = 123;
    start_time = uclock();
    for (i = 0; i < TOTAL_ITERATIONS; i++)
    {
      automatic_uint = automatic_uint + THE_VALUE;
    }
    end_time = uclock();
    cout << "automatic, PLUS [" << (t + 1) << "] Total time : " <<
(end_time - start_time) << endl;
  }
  cout << automatic_uint << endl;

  return 0;
}

|| ###### C++ code : END ########


|| ###### Compilation & Run : BEGIN ########
|| No optimization

%gpp main.c -o a0.exe

%a0


--- static uint with OR ---
static, OR [1] Total time : 30
static, OR [2] Total time : 25
static, OR [3] Total time : 27
static, OR [4] Total time : 27
static, OR [5] Total time : 28
static, OR [6] Total time : 28
static, OR [7] Total time : 26
static, OR [8] Total time : 27
static, OR [9] Total time : 27
static, OR [10] Total time : 27
1

--- automatic uint with OR ---
automatic, OR [1] Total time : 23
automatic, OR [2] Total time : 23
automatic, OR [3] Total time : 24
automatic, OR [4] Total time : 24
automatic, OR [5] Total time : 23
automatic, OR [6] Total time : 23
automatic, OR [7] Total time : 23
automatic, OR [8] Total time : 23
automatic, OR [9] Total time : 23
automatic, OR [10] Total time : 23
1


--- static uint with PLUS ---
static, PLUS [1] Total time : 20
static, PLUS [2] Total time : 21
static, PLUS [3] Total time : 20
static, PLUS [4] Total time : 20
static, PLUS [5] Total time : 20
static, PLUS [6] Total time : 20
static, PLUS [7] Total time : 20
static, PLUS [8] Total time : 20
static, PLUS [9] Total time : 21
static, PLUS [10] Total time : 20
52123

--- automatic uint with PLUS ---
automatic, PLUS [1] Total time : 24
automatic, PLUS [2] Total time : 24
automatic, PLUS [3] Total time : 17
automatic, PLUS [4] Total time : 18
automatic, PLUS [5] Total time : 18
automatic, PLUS [6] Total time : 17
automatic, PLUS [7] Total time : 17
automatic, PLUS [8] Total time : 18
automatic, PLUS [9] Total time : 17
automatic, PLUS [10] Total time : 18
52123

|| No optimization
|| ###### Compilation & Run : END ##########




|| ###### Compilation & Run : BEGIN ########
|| Optimization O1

%gpp -O1 main.c -o a1.exe

%a1

--- static uint with OR ---
static, OR [1] Total time : 35
static, OR [2] Total time : 34
static, OR [3] Total time : 35
static, OR [4] Total time : 34
static, OR [5] Total time : 35
static, OR [6] Toll time : 35
static, OR [7] Total time : 34
static, OR [8] Total time : 34
static, OR [9] Total time : 34
static, OR [10] Total time : 34
1

--- automatic uint with OR ---
automatic, OR [1] Total time : 28
automatic, OR [2] Total time : 28
automatic, OR [3] Total time : 28
automatic, OR [4] Total time : 27
automatic, OR [5] Total time : 28
automatic, OR [6] Total time : 28
automatic, OR [7] Total time : 27
automatic, OR [8] Total time : 28
automatic, OR [9] Total time : 27
automatic, OR [10] Total time : 27
1


--- static uint with PLUS ---
static, PLUS [1] Total time : 14
static, PLUS [2] Total time : 15
static, PLUS [3] Total time : 14
static, PLUS [4] Total time : 14
static, PLUS [5] Total time : 14
static, PLUS [6] Total time : 15
static, PLUS [7] Total time : 14
static, PLUS [8] Total time : 15
static, PLUS [9] Total time : 14
static, PLUS [10] Total time : 14
52123

--- automatic uint with PLUS ---
automatic, PLUS [1] Total time : 14
automatic, PLUS [2] Total time : 15
automatic, PLUS [3] Total time : 14
automatic, PLUS [4] Total time : 15
automatic, PLUS [5] Total time : 14
automatic, PLUS [6] Total time : 15
automatic, PLUS [7] Total time : 14
automatic, PLUS [8] Total time : 14
automatic, PLUS [9] Total time : 14
automatic, PLUS [10] Total time : 14
52123

|| Optimization O1
|| ###### Compilation & Run : END ##########



|| ###### Compilation & Run : BEGIN ########
|| Optimization O2

%gpp -O2 main.c -o a2.exe

%a2

--- static uint with OR ---
static, OR [1] Total time : 36
static, OR [2] Total time : 33
static, OR [3] Total time : 34
static, OR [4] Total time : 33
static, OR [5] Total time : 34
static, OR [6] Total time : 35
static, OR [7] Total time : 34
static, OR [8] Total time : 33
static, OR [9] Total time : 34
static, OR [10] Total time : 34
1

--- automatic uint with OR ---
automatic, OR [1] Total time : 27
automatic, OR [2] Total time : 27
automatic, OR [3] Total time : 26
automatic, OR [4] Total time : 28
automatic, OR [5] Total time : 26
automatic, OR [6] Total time : 27
automatic, OR [7] Total time : 28
automatic, OR [8] Total time : 27
automatic, OR [9] Total time : 28
automatic, OR [10] Total time : 27
1


--- static uint with PLUS ---
static, PLUS [1] Total time : 21
static, PLUS [2] Total time : 21
static, PLUS [3] Total time : 14
static, PLUS [4] Total time : 21
static, PLUS [5] Total time : 14
static, PLUS [6] Total time : 21
static, PLUS [7] Total time : 15
static, PLUS [8] Total time : 21
static, PLUS [9] Total time : 15
static, PLUS [10] Total time : 21
52123

--- automatic uint with PLUS ---
automatic, PLUS [1] Total time : 12
automatic, PLUS [2] Total time : 12
automatic, PLUS [3] Total time : 12
automatic, PLUS [4] Total time : 12
automatic, PLUS [5] Total time : 12
automatic, PLUS [6] Total time : 12
automatic, PLUS [7] Total time : 12
automatic, PLUS [8] Total time : 11
automatic, PLUS [9] Total time : 13
automatic, PLUS [10] Total time : 12
52123

|| Optimization O2
|| ###### Compilation & Run : END ##########




|| ###### Compilation & Run : BEGIN ########
|| Optimization O3

%gpp -O3 main.c -o a3.exe

%a3
--- static uint with OR ---
static, OR [1] Total time : 36
static, OR [2] Total time : 34
static, OR [3] Total time : 34
static, OR [4] Total time : 33
static, OR [5] Total time : 34
static, OR [6] Total time : 34
static, OR [7] Total time : 34
static, OR [8] Total time : 34
static, OR [9] Total time : 34
static, OR [10] Total time : 34
1

--- automatic uint with OR ---
automatic, OR [1] Total time : 27
automatic, OR [2] Total time : 27
automatic, OR [3] Total time : 28
automatic, OR [4] Total time : 27
automatic, OR [5] Total time : 28
automatic, OR [6] Total time : 28
automatic, OR [7] Total time : 28
automatic, OR [8] Total time : 27
automatic, OR [9] Total time : 28
automatic, OR [10] Total time : 27
1


--- static uint with PLUS ---
static, PLUS [1] Total time : 14
static, PLUS [2] Total time : 15
static, PLUS [3] Total time : 15
static, PLUS [4] Total time : 14
static, PLUS [5] Total time : 15
static, PLUS [6] Total time : 15
static, PLUS [7] Total time : 15
static, PLUS [8] Total time : 14
static, PLUS [9] Total time : 14
static, PLUS [10] Total time : 15
52123

--- automatic uint with PLUS ---
automatic, PLUS [1] Total time : 12
automatic, PLUS [2] Total time : 12
automatic, PLUS [3] Total time : 12
automatic, PLUS [4] Total time : 12
automatic, PLUS [5] Total time : 13
automatic, PLUS [6] Total time : 12
automatic, PLUS [7] Total time : 12
automatic, PLUS [8] Total time : 12
automatic, PLUS [9] Total time : 12
automatic, PLUS [10] Total time : 12
52123

|| Optimization O3
|| ###### Compilation & Run : END ##########


--
  ===========================
  Alex Vinokur
    mailto:alexvn AT bigfoot DOT com
    mailto:alexvn AT go DOT to
    http://up.to/alexvn
    http://go.to/alexv_math
  ===========================


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019