Skip to content

Possible optimization by looping on two bytes at a time #29

@tigrouind

Description

@tigrouind

Have you considered a possible optimization by looping on the array 2 bytes at a time ? This can be done using pointers :

For example :

fixed (byte* dataPtr = data)
{
      	ushort* ushortPtr = (ushort*)dataPtr;
        for (int i = 0 ; i < data.Length / 2; i++)
        {
                ushort value = *ushortPtr++;
        }
}

The idea would be to use the ushort directly. If you have to split it into two bytes (eg: using a byte shift or a struct with some clever packing) you probably lose the speed gain.
I don't know if a 16-bit 65536 entries lookup table could be used. Tradeoff is it might not fit in CPU cache.
I saw your implementation that deals with 16 bytes at a time. Maybe this could be done as well here. Like processing 8 bytes at a time but with ushorts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions