www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/06/04/12:53:33

From: "Heinz Ozwirk" <wansor42 AT gmx DOT de>
Newsgroups: comp.os.msdos.djgpp,comp.lang.c++
Subject: Re: Optimization and operator&&
Date: Tue, 4 Jun 2002 17:42:18 +0200
Organization: T-Online
Lines: 93
Message-ID: <adin9l$s7q$00$1@news.t-online.com>
References: <3CFCB642 DOT 252CFFF7 AT bigfoot DOT com> <adigc2$n1d$03$1 AT news DOT t-online DOT com> <3CFCDBF9 DOT CCDA33 AT bigfoot DOT com>
Mime-Version: 1.0
X-Trace: news.t-online.com 1023205494 00 28922 RF56bMbXSrAJYk 020604 15:44:54
X-Complaints-To: abuse AT t-online DOT com
X-Sender: 320053623259-0001 AT t-dialin DOT net
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Alex Vinokur" <alexvn AT bigfoot DOT com> wrote in message
news:3CFCDBF9 DOT CCDA33 AT bigfoot DOT com...
> --- static uint with OR ---
> static, OR [1] Total time : 186986
> static, OR [2] Total time : 187100
> static, OR [3] Total time : 181918
> static, OR [4] Total time : 193440
> static, OR [5] Total time : 177352
> static, OR [6] Total time : 182445
> static, OR [7] Total time : 185969
> static, OR [8] Total time : 204047
> static, OR [9] Total time : 176972
> static, OR [10] Total time : 191458
> 1

I must admit, that I still don't like those results. They still differ by
about 15%. What does the uclock() function, you are using measure. Is it
some "real" time or is it the processor time, the program has actually used.
I tried your code with VC.Net and got results like these (1,000,000
iterations):

Optimizations disabled:
--- automatic uint with OR ---
automatic, OR [1] Total time : 1392
automatic, OR [2] Total time : 1392
automatic, OR [3] Total time : 1402
automatic, OR [4] Total time : 1392
automatic, OR [5] Total time : 1392
automatic, OR [6] Total time : 1392
automatic, OR [7] Total time : 1392
automatic, OR [8] Total time : 1412
automatic, OR [9] Total time : 1402
automatic, OR [10] Total time : 1392
1


--- static uint with PLUS ---
static, PLUS [1] Total time : 651
static, PLUS [2] Total time : 641
static, PLUS [3] Total time : 641
static, PLUS [4] Total time : 631
static, PLUS [5] Total time : 651
static, PLUS [6] Total time : 641
static, PLUS [7] Total time : 651
static, PLUS [8] Total time : 641
static, PLUS [9] Total time : 641
static, PLUS [10] Total time : 651
905032827


Optimized for speed:
--- automatic uint with OR ---
automatic, OR [1] Total time : 511
automatic, OR [2] Total time : 501
automatic, OR [3] Total time : 500
automatic, OR [4] Total time : 501
automatic, OR [5] Total time : 501
automatic, OR [6] Total time : 511
automatic, OR [7] Total time : 500
automatic, OR [8] Total time : 501
automatic, OR [9] Total time : 501
automatic, OR [10] Total time : 500
1


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

Here, the optimized && (AND, not OR, btw.) is almost three times as fast as
with optimizations turned off, and the 1,000,000 iterations for + cannot be
measured, probably because VC.Net computed the result at compile time. (I
don't know why it didn't do so for &&)

But that doesn't answer your question, and I cannot do so. Common sense
suggests that optimized code should be faster than plain code and if a
compiler slows down a program when optimizing might be a hint that the
compiler does something wrong. Or the uclock() function is not the proper
tool for timing code.

Regards
    Heinz


- Raw text -


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