note 75061 added to function.crc32
| From: | manuel at sadism-softworks dot de | Date: | Thu, 10 May 2007 13:35:17 +0000 |
| Subject: | note 75061 added to function.crc32 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126387@lists.php.net to get a copy of this message | ||
In response to quix at free dot fr (http://www.php.net/manual/de/function.crc32.php#31832):
Through buffering his CRC32 calculation is about 2-4 times faster:
<?php
function __crc32_file($name)
{
// Creates a CRC from a file
// Info: look at __crc32_string
global $__crc32_table;
// Start out with all bits set high.
$crc = 0xffffffff;
// Open the file
$fp = fopen($name, "rb");
// Read the file using a 1MB buffer
// This will speed up CRC calculation at least 2-4x!
// (5MB file: 15sec instead of 50sec)
if ($fp != false)
{
$buffer = '';
while (!feof($fp))
{
$buffer = fread($fp, 1048576); // Buffer 1MByte of file into memory
$len = strlen($buffer); // Cache buffer length (just this saves about 10sec on a 5MB
file!)
for ($i = 0; $i < $len; $i++)
{
$crc = (($crc >> 8) & 0x00ffffff) ^ $__crc32_table[($crc & 0xFF) ^
ord($buffer[$i])];
}
}
fclose($fp);
}
// Exclusive OR the result with the beginning value.
return $crc ^ 0xffffffff;
}
?>
----
Server IP: 217.160.72.57
Probable Submitter: 194.31.246.249
----
Manual Page -- http://www.php.net/manual/en/function.crc32.php
Edit -- https://master.php.net/note/edit/75061
Del: integrated -- https://master.php.net/note/delete/75061/integrated
Del: useless -- https://master.php.net/note/delete/75061/useless
Del: bad code -- https://master.php.net/note/delete/75061/bad+code
Del: spam -- https://master.php.net/note/delete/75061/spam
Del: non-english -- https://master.php.net/note/delete/75061/non-english
Del: in docs -- https://master.php.net/note/delete/75061/in+docs
Del: other reasons-- https://master.php.net/note/delete/75061
Reject -- https://master.php.net/note/reject/75061
Search -- https://master.php.net/manage/user-notes.php