Re: crc32() improvements

From: Date: Mon, 14 Jun 2004 08:51:48 +0000
Subject: Re: crc32() improvements
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-10431@lists.php.net to get a copy of this message
On Sun, 13 Jun 2004 23:10:04 +0000, Curt Zirzow <curt@php.net> 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 <stdio.h> #include <time.h> /* 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/

« previous php.internals (#10431) next »