Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10426 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4506 invoked by uid 1010); 13 Jun 2004 23:02:19 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 4444 invoked from network); 13 Jun 2004 23:02:18 -0000 Received: from unknown (HELO took.shire) (68.126.141.9) by pb1.pair.com with SMTP; 13 Jun 2004 23:02:18 -0000 Received: (qmail 53421 invoked by uid 1001); 13 Jun 2004 23:10:04 -0000 Date: Sun, 13 Jun 2004 23:10:04 +0000 To: internals@lists.php.net Message-ID: <20040613231004.GL80292@bagend.shire> Mail-Followup-To: internals@lists.php.net References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i Subject: Re: [PHP-DEV] crc32() improvements From: curt@php.net (Curt Zirzow) * 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. > 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. > 3) Less source size. Current verison has near 6.5Kb length > (including crc32.h). My version has only 2.5Kb length. Source size is futile. > > Below I provided a test (just copy->compile->test) > and unified diff of /ext/standard/crc32.c > ... > > /****************************************************/ > /* my crc32 function */ > PHP_NAMED_FUNCTION(php_if_crc32) > { > static unsigned long int crc32tab[256], not_init = 1; > if (not_init) { > /* init crc32 table */ > register unsigned long int tmp, i, j, flag_c; > for (i = 0; i < 256; i++) { > tmp = i; > j = 8; > do { > if (tmp & 1) { > tmp >>= 1; > tmp ^= 0xEDB88320; /* CRC32 > (CCITT-32) poly g(x) = 1 0000 0100 > 1100 0001 0001 1101 1011 0111 */ > } else tmp >>= 1; > j--; > } while (j); > crc32tab[i] = tmp; > } > not_init = 0; > } > /* crc32 calculations */ > char *str; > int len; > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len) > == FAILURE || len < 0) return; Have you read CODING_STANDARDS yet? Curt -- I was working on a flat tax proposal, and I accidentally proved there's no god.