Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1157 (closed enhancement: fixed)

Opened 3 months ago

Last modified 2 months ago

tango.io.digest.Crc32 speed-up

Reported by: gim Assigned to: kris
Priority: major Milestone: 0.99.8
Component: IO Version: 0.99.6 Jeff
Keywords: crc32 Cc:

Description

I would like to propose the following change in update method:

instead of current:

    r &= 0xFFFFFF00;
    r /= 0x100;
    r &= 16777215;

change it to:

    r >>>= 8;

this should improve speed of calculating crc a bit.

similiar code is also present in ctor, but it's short loop, and usually called much less times than update, but readability could be imporved:

current:

        if (value & 1) {
                value &= 0xFFFFFFFE;
                value /= 2;
                value &= 0x7FFFFFFF;
                value ^= polynomial;
        }
        else
        {
                value &= 0xFFFFFFFE;
                value /= 2;
                value &= 0x7FFFFFFF;
        }

to:

        if (value & 1)
                value >>>=1, value ^= polynomial;
        else
                value >>>=1;

If there are any reasons for keeping & + /= + & instead of >>> please write them below.

Testing on 350M file on my computer gives avarage times 6.55 secs for old version and 5.65 secs for new one that gives about 16% speed-up.

Change History

06/25/08 13:52:51 changed by kris

  • status changed from new to assigned.
  • milestone changed from 0.99.7 to 0.99.8.

nice!

07/16/08 11:38:03 changed by mandel

*bump* fwiw, I verified it with current dmd and gdc. Not the speedup, only that it works; >>>= is so hard to google :P

07/17/08 13:21:15 changed by mandel

value >>>=1, value ^= polynomial;

The comma is a typo. Should be a ';'.

08/03/08 13:17:35 changed by kris

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [3836]) fixes #1157 :: tango.io.digest.Crc32 speed-up (with version, for now)

thanks to gim