[Cryptography] It's all K&R's fault
Patrick Chkoreff
patrick at rayservers.net
Sun Apr 20 09:00:51 EDT 2014
Patrick Chkoreff wrote, On 04/20/2014 08:45 AM:
> I even leave bounds checking enabled in extremely low-level code, such
> as in this fast buffering routine:
>
> https://github.com/chkoreff/Fexl/blob/fresh/src/buf.c#L36
>
> I benchmarked buffering up a 2.6 GB string, one character at a time,
> with and without that bounds checking assertion, and I saw no
> statistically significant difference in run time.
Sorry, I meant to say 2.0 GB. The buf uses an int size anyway so it
couldn't hold 2.6 GB. :) And yes, I do have various guards in place to
prevent integer overflows, including in the language itself, which (will
soon) use only unbounded math operators by default, including integers
and rationals of unlimited size.
Here are the details from a previous email to a colleague:
~@@@@
...
What the heck, let's try an even 2 GB:
$ ./build && time ../bin/run
Compile run
Link run
: Buffering 2000000000 bytes
length = 2000000000
real 0m13.350s
user 0m12.049s
sys 0m1.288s
Ah, but what if I remove my range check?
$ ./build && time ../bin/run
Compile buf
Link run
: Buffering 2000000000 bytes
length = 2000000000
real 0m13.103s
user 0m11.781s
sys 0m1.312s
Repeated testing of both ways shows no significant difference.
I think I'll leave in the range check.
Range checks also support one of my favorite programming maxims:
No Silent Failure!
@@@@
-- Patrick
More information about the cryptography
mailing list