Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10431 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18775 invoked by uid 1010); 14 Jun 2004 08:52:46 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 17918 invoked by uid 1007); 14 Jun 2004 08:52:38 -0000 To: internals@lists.php.net Date: Mon, 14 Jun 2004 11:51:48 +0300 References: <20040613231004.GL80292@bagend.shire> Organization: none Content-Type: text/plain; format=flowed; delsp=yes; charset=koi8-r MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: User-Agent: Opera M2/7.50 (Win32, build 3778) X-Posted-By: 217.23.116.150 Subject: Re: [PHP-DEV] crc32() improvements From: valyala@tut.by ("Alexander Valyalkin") On Sun, 13 Jun 2004 23:10:04 +0000, Curt Zirzow wrote: > * Thus wrote Alexander Valyalkin (valyala@tut.by): >> Here is improved version of crc32() function. >> Features: >> 1) Automatic initialization of crc32tab[] at first call. >> So, the file crc32.h with definition of this tab is not >> nessesary any more now. > > I'm not sure what advantage this is really giving you being that > gcc will optimize where the data segment should be, vs putting the > data directly into php's memory. > Yes, it's my fault. > >> 2) Speed is improved on large amount of data. > > By using a registered int with a do while() statement vs a > foreach() statement, I'd like to see some benchmarks against this. > Well. Try something like this: ===================cut=================== #include #include /* for use _rdtsc() */ #define N 10 * 1000 * 1000 int main(int argc,char *argv[]) { unsigned long long int t; unsigned int i; unsigned int crc = ~0; t = _rdtsc(); for (i = 0; i < N; i++) { crc ^= i; } printf("speed of for (i++) loop: %llu\n", _rdtsc() - t); i = N; t = _rdtsc(); for ( ; i--; ) { crc ^= i; } printf("speed of for (i--) loop: %llu\n", _rdtsc() - t); i = N; t = _rdtsc(); if (i > 0) do { crc ^=i; } while (--i); printf("speed of do while loop: %llu\n", _rdtsc() - t); return 0; } ===================cut=================== -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/