Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 38192 invoked from network); 10 Oct 2005 07:09:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Oct 2005 07:09:24 -0000 Received: (qmail 96754 invoked by uid 500); 10 Oct 2005 07:09:19 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 96698 invoked by uid 500); 10 Oct 2005 07:09:18 -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 96687 invoked by uid 99); 10 Oct 2005 07:09:17 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Oct 2005 00:09:17 -0700 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=FORGED_RCVD_HELO X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [212.39.12.10] (HELO deck1210.hostdeck.com) (212.39.12.10) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Oct 2005 00:09:17 -0700 Received: (qmail 13872 invoked from network); 10 Oct 2005 09:08:51 +0200 Received: from host70-41.pool82106.interbusiness.it (HELO fatti.com) (82.106.41.70) by deck1210.hostdeck.com with SMTP; 10 Oct 2005 09:08:50 +0200 Message-ID: <434A13CC.9070307@fatti.com> Date: Mon, 10 Oct 2005 09:10:04 +0200 From: Enrico Migliore Reply-To: enrico.migliore@fatti.com Organization: - User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 To: harmony-dev@incubator.apache.org Subject: optimization for speed in win32 References: <4120051057161659260@earthlink.net> <8957062C-C689-47FC-A8D8-AD850232151C@apache.org> <4346B809.1090209@fatti.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed 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 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 (**) __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