in reply to Re^4: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
in thread Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
by mr_mischief (Monsignor) on Sep 13, 2007 at 16:36 UTC | |
dragonchild's statement above is correct. chr(0) is a touch less efficient than "\0" or just plain 0 it seems, but not nearly so much as to make any difference in the real world. Still, the tests pass with the wrong string. The version of the benchmark and test code I grabbed from an earlier node must've reinforced my blunder. Read more... (2 kB) | [reply] [d/l] [select] |
by dragonchild (Archbishop) on Sep 13, 2007 at 16:50 UTC | |
Tossing in bytes::chr() slowed your version down even more. :-( Update: Corrected per ikegami's response. My criteria for good software: | [reply] |
by ikegami (Patriarch) on Sep 13, 2007 at 17:19 UTC | |
NULL is a special pointer in C, and an exceptional value in in SQL and VB.
I believe you are refereing to NUL. | [reply] [d/l] [select] |
by mr_mischief (Monsignor) on Sep 13, 2007 at 17:52 UTC | |
by ikegami (Patriarch) on Sep 13, 2007 at 18:36 UTC | |
| |
by mr_mischief (Monsignor) on Sep 13, 2007 at 18:23 UTC | |
Look at an ASCII chart (2, 3, 4). What's at position 0? It's a byte with all zeros, and yes it's called NUL. It's also referred to as a 'null byte' (all lowercase, four letters). While it's true a null/zero byte can represent something other than NUL, NUL is always represented as a null/zero byte (at least in ASCII and EBCDIC).
When dealing with eight-bit bytes, it shouldn't matter if you have an ASCII character, I don't need your beer. I'm just trying to help. You can do whatever you like, but I'm not sure where you're getting the idea that '\0' is producing a different end product in these cases. Try "\000" or "\x00" instead, and see if it changes anything at all. I'm guessing using chr(0) is changing absolutely nothing but the speed. Update: and I based this on the results of the Test::More tests that said it was all producing the same output. Apparently, either it's working by some fluke, or the tests are broken. Take a look at this:
and here's the code:
If you don't trust Test::More, I guess you could make smaller sample data strings and visually inspect them. Update:Maybe we should trust Test::More, but take a more carefullook at the tests for the benchmarking and testing code being used from above. | [reply] [d/l] [select] |
by ikegami (Patriarch) on Sep 13, 2007 at 19:32 UTC | |
by ikegami (Patriarch) on Sep 13, 2007 at 19:14 UTC | |
|
Re^6: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
by mr_mischief (Monsignor) on Sep 13, 2007 at 21:08 UTC | |
And this is with this code:
| [reply] [d/l] [select] |
by ikegami (Patriarch) on Sep 14, 2007 at 02:05 UTC | |
I fixed the in-place tests so they actually worked on the intended test data. And to make the benchmarks worth anything, I made inline those that weren't inline. By the way, mrm_3 looped forever if $s1 contained a NUL. I fixed it by adding a + 1 to index's last arg. Read more... (6 kB)
| [reply] [d/l] [select] |
by mr_mischief (Monsignor) on Sep 14, 2007 at 14:39 UTC | |
The fastest pure-Perl solution in every case seems to be mrm_5, and usually by a decent margin. That's a version of moritz's code slightly tweaked with some of the tips taken from avar's code. moritz's own code (as tweaked for in-place fairness by ikegami) seems to be near the top quite consistently. So if pure Perl speed is the goal, moritz seems to have been on the right track all along. As my code for mrm_5 is just variations on improving his, I think he should get most of the credit for it (especially since he didn't go stupid halfway through and break it like I did). Strawberry 5.8.8 on WinXP, AthlonXP 2400+, 1GB Read more... (3 kB)
ActivePerl 5.8.0 on same machine
Died during tests
cygperl 5.8.7 on same machine Read more... (3 kB)
perl 5.8.7 on Mandriva 2006, Athlon 1000, 512 MB
Read more... (3 kB)
perl 5.9.5 (gcc 4.0.1, -O4 (4.0.1-5mdk)) on the above Mandriva
Read more... (3 kB)
Just for kicks: miniperl 5.9.5 on Mandriva Read more... (3 kB)
| [reply] [d/l] [select] |
by ikegami (Patriarch) on Sep 14, 2007 at 01:14 UTC | |
| [reply] [d/l] |