Multi-file byte comparison tool. What would you have done differently?

Kai Meyer kai at unixlords.com
Mon Aug 8 10:33:37 PDT 2011


On 08/08/2011 12:33 AM, Pelle wrote:
> On Fri, 05 Aug 2011 18:43:27 +0200, Kai Meyer <kai at unixlords.com> wrote:
>
>> On 08/05/2011 03:02 AM, Pelle wrote:
>>>
>>> Don't declare variables until you need them, just leave bytes_read and
>>> bytes_max here.
>>>
>> Is there a performance consideration? Or is it purely a style or
>> D-Factor suggestion?
>
> Just style and D-factor :-)
>
> Also, resulting code is shorter, and you can replace a lot of type names
> with auto.
>
>>> I don't understand why you use ByteUnion instead of just a plain array
>>> of bytes.
>> I thought that comparing one byte at a time would be slower than
>> comparing 8 bytes at a time (size_t on 64bit) and failing over to the
>> byte-by-byte comparison only when the size_t value was different.
>
> Maybe, but that's something that should be benchmarked. If a byte array
> is just as fast, and the code is simpler, that's a better solution :)


I simply can't imagine how 8,000 byte comparisons would be even close to 
comparable to 1,000 size_t comparisons done one at a time, with the way 
I'm doing the comparison. I'm certain there are much better ways of 
comparing bits, but I'm not ready to make this program that complex :)


More information about the Digitalmars-d-learn mailing list