From harmony-dev-return-2746-apmail-incubator-harmony-dev-archive=incubator.apache.org@incubator.apache.org Sat Dec 03 17:44:30 2005 Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 56743 invoked from network); 3 Dec 2005 17:44:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Dec 2005 17:44:29 -0000 Received: (qmail 39418 invoked by uid 500); 3 Dec 2005 17:44:26 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 39291 invoked by uid 500); 3 Dec 2005 17:44:25 -0000 Mailing-List: contact harmony-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-dev@incubator.apache.org Received: (qmail 39280 invoked by uid 99); 3 Dec 2005 17:44:25 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Dec 2005 09:44:25 -0800 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: 217.155.92.109 is neither permitted nor denied by domain of ben@algroup.co.uk) Received: from [217.155.92.109] (HELO mail.links.org) (217.155.92.109) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Dec 2005 09:44:23 -0800 Received: from [193.133.15.218] (localhost [127.0.0.1]) by mail.links.org (Postfix) with ESMTP id A2E7C33C1C for ; Sat, 3 Dec 2005 17:44:02 +0000 (GMT) Message-ID: <4391D970.40909@algroup.co.uk> Date: Sat, 03 Dec 2005 17:44:16 +0000 From: Ben Laurie User-Agent: Thunderbird 1.5 (Windows/20051025) MIME-Version: 1.0 To: harmony-dev@incubator.apache.org Subject: Re: optimization for speed in win32 References: <4120051057161659260@earthlink.net> <8957062C-C689-47FC-A8D8-AD850232151C@apache.org> <4346B809.1090209@fatti.com> <434A13CC.9070307@fatti.com> In-Reply-To: <434A13CC.9070307@fatti.com> X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Blast from the past here... Enrico Migliore wrote: > Hi, > > I did some tests in order to see which, among __fastcall, __stdcall, > __cdecl, __inline, > gives the fastest execution time: my_functions() was called 300000000 > times > > Processor = Intel Pentium 1.4 GHz > OS = Windows 2000 > Compiler = Microsoft Visual C > Executable type = release > > ---------------------- code ------------------------------ > #include > #include > > /* > * qualifier: __fastcall, __stdcall, __cdecl, __inline > */ > qualifier int my_function (int a, char *buf) > { > > int int_1 = 1987; > char char_1 = 'a'; > long long_1 = 123456789L; > long long_2 = &long_1; > > if (a > 0) > { > a++; > } > else > { > a--; > } > if (int_1 > 9) > { > char_1++; > } > else > { > char_1--; > } > *long_2++; > if (buf == NULL) > { > return -1; > } > buf++; > return a; > } > > > double test (void) > { > > long i; > int result; > char buf[8]; > clock_t start; > clock_t stop; > double duration; > > buf[0] = 0; > > start = clock(); for (i = 0; i < 300000000; i++) > { > result = my_function(10,buf); > } > stop = clock(); > duration = (double) (stop - start) / CLOCKS_PER_SEC; > > return duration; > } > > > Results: > > -------------------------------------------------------- > qualifier | test duration (maximize for speed = OFF) > -------------------------------------------------------- > __fastcall | 14.3900 seconds > __stdcall | 12.9700 seconds > __cdecl (**) | 13.6200 seconds > __inline | 12.9600 seconds > > -------------------------------------------------------- > qualifier | test duration (maximize for speed = ON) > -------------------------------------------------------- > __fastcall | 5.9400 seconds > __stdcall | 6.5300 seconds > __cdecl (**) | 6.4800 seconds > __inline | 0.0000 seconds (*) > > (*) suspicious Actually, this is not suspicious - if the function is inlined, the compiler can optimise the loop away. This is a common flaw with benchmark code - not as smart as the compiler is :-) > (**) __cdecl is the default qualifier > > > > Conclusion: > > __inline and __fastcall give the best results > when the compiler is instructed to generate code > with the flag "optimize for speed" enabled. > > I also noticed that parameters marshalling is not an issue > because the compiler will link the appropriate static library according > to the optimization selected. Therefore, in win32, we should > be able to optimize our C code for speed without problems. > > Enrico > > -- http://www.apache-ssl.org/ben.html http://www.thebunker.net/ ** ApacheCon - Dec 10-14th - San Diego - http://apachecon.com/ ** "There is no limit to what a man can do or how far he can go if he doesn't mind who gets the credit." - Robert Woodruff