How to optimize this? (a check-sum calculator) 
Author Message
 How to optimize this? (a check-sum calculator)

I'm dabbling a bit in perl, and I would like to hear your opinions on how
to optimize the following function, so that it will run faster?

-----------
sub sum {

    local ($length, $buffer, $i, $summer);

    $summer = 0;
    open(FILEHANDLE, $file_name) ||
        die "Can't open file to read...";
    $length = read(FILEHANDLE, $buffer, 256);
    for ($i = 0; $i < $length; $i++) {
        $summer += vec($buffer,$i,1);
        $summer <<= 1;
    }
    seek(FILEHANDLE, -256, 2);
    $length = read(FILEHANDLE, $buffer, 256);
    for ($i = 0; $i < $length; $i++) {
        $summer += vec($buffer, $i, 1);
        $summer <<= 1;
    }
    close(FILEHANDLE);
    return $summer;

Quote:
}

----

Now, the idea is to get a 'quick' check-sum for each file I'm running this
program on, but apparently this function is now the bottle neck in my
program.  Has anyone any ideas on how to speed this function up?

(See, even here in Iceland, we use perl :-)

--



Fri, 16 Feb 1996 07:37:53 GMT  
 How to optimize this? (a check-sum calculator)
Check out the % format in unpack for checksumming.

--tom
--



Fri, 16 Feb 1996 08:59:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Unpack checksum doesn't match BSD sum

2. problem with the UNIX sum checksum command and unpack

3. UDP / ICMP checksum generation - 1's complement sum

4. Check Sum Program for Internet Server Files (HTML's, JPG's, etc)

5. UDP / ICMP checksum generation - 1's complement sum

6. **Need Calculator Script*

7. HP-style calculator in perl

8. Limited form of eval() - just a calculator

9. Date subroutines and calculator

10. Perl as a pocket calculator

11. gtkperl finacial calculator NEW!

12. Simple Permutation Calculator

 

 
Powered by phpBB® Forum Software