Benchmark::bm do |x|
test_algorithm = lambda do |id|
x.report id.to_s do
whitespace_tester = $whitespace.method id
nonwhitespace_tester = $nonwhitespace.method id
n.times { whitespace_tester.call }
n.times { nonwhitespace_tester.call }
end
end
test_algorithm.call :henrik
test_algorithm.call :evan
test_algorithm.call :mikael
test_algorithm.call :tonoma
end
<Ara.T.Howard@noaa.gov> schrieb im Newsbeitrag
news:Pine.LNX.4.60.0409230933170.2168@harp.ngdc.noaa.gov...
>
> "ts" <decoux@moulon.inra.fr> schrieb im Newsbeitrag
> news:200409231451.i8NEphE08333@moulon.inra.fr...
>>
>> > if s.strip.empty?
>> > # the string is whitespace only
>>
>> svg% ruby -e 'a = " \000\000"; p "OK" if a.strip.empty?'
>> "OK"
>> svg%
>>
>> svg% ruby -e 'a = " \000\000 "; p "OK" if a.strip.empty?'
>> svg%
>
> Also I'd say the disadvantage of "a.strip.empty?" is that it creates a
copy
> of the string (=> a new instance) which is generally slower than a
simple
> regexp check.
i assumed you were correct - but this is suprising:
man isspace
...
isspace()
checks for white-space characters. In the "C" and "POSIX"
locales, these are: space, form-feed ('\f'), newline ('\n'),
carriage return ('\r'), horizontal tab ('\t'), and vertical tab
('\v').
...
from wikipedia
In computer science, a whitespace (or a whitespace character) is any
character which does not display itself but does take up space. For example,
the character symbol " ", which is a blank space. Whitespaces are generated by
the space bar or the Tab key; depending on context, a line-break generated by
the Return key (Enter key) may be considered whitespace as well.
Whitespace can also refer to a series of whitespace characters. Within source
code, the size of whitespace is generally ignored by free-form languages. In
the Python programming language whitespace and indentation are used for
syntactical purposes.
In many programming languages abundant use of whitespace, especially trailing
whitespace at the end of lines, is considered a nuisance.
[ \t]+ is a regular expression that matches whitespace.
The term whitespace is based on the assumption that the background color used
for text is white, and is thus confusing if it is not.
there is a long standing precendent for the meaning of whitespace. it does not
include non-printables since that do not take up any __space__. for that there
is isgraph(3)
-a
···
On Fri, 24 Sep 2004, Markus wrote:
On Thu, 2004-09-23 at 08:34, Ara.T.Howard@noaa.gov wrote:
since when is NUL whitespace!? defintely against POLS.
???
Since when _isn't_ NUL whitespace? Despite the fact that it is sometimes
used as a delimiter (which is true for all the other whitespace characters
as well), it has no meaning, no glyph, does not show up when printed--it
doesn't even move the cursor/printhead. How much more "whitespace" can you
get?
--
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen
why useless? you mean because there's nothing to interplate here - that's
true in this case...
what do you mean be complex? seems very simple?
-a
···
On Fri, 24 Sep 2004, ts wrote:
> rep = %r/^\s*$/o
/o is useless and you make something too complex for the regexp engine
--
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen
Gosh. So I guess your answer to my question is "since the late
1970's or so", which, coincidentally, is most likely the last time I
checked. Back in the RS-232 paper tape and teletype days (ASCII)
whitespace was the same as non-printing, e.g. everything <= 040 and
sometimes 0177, while the EBCDIC definition was a little murkier.
*laugh* I wonder if anything else has changed in the last thirty
years?
Thanks,
-- Markus
···
On Thu, 2004-09-23 at 09:44, Ara.T.Howard@noaa.gov wrote:
On Fri, 24 Sep 2004, Markus wrote:
> On Thu, 2004-09-23 at 08:34, Ara.T.Howard@noaa.gov wrote:
>
>> since when is NUL whitespace!? defintely against POLS.
>
> ???
>
> Since when _isn't_ NUL whitespace?
doesn't this make the arrays the same? Isn't $nonwhitespace just a
reference to $whitespace?
Er, yes. Duh. I haven't really awoken yet. Duping whitespace doesn't
make any real difference, though. More interesting results are found
when whitespace[0] = 'a'. With n = 10000 and $nonwhitespace ignored
entirely:
user system total real
henrik 14.140000 0.060000 14.200000 ( 14.684509)
evan 0.110000 0.030000 0.140000 ( 0.146974)
mikael 0.040000 0.020000 0.060000 ( 0.060418)
tonoma 3.840000 0.040000 3.880000 ( 4.163754)
perhaps i was a bit to aggressive in that reply - you sarcasm gave me a good
laugh at myself. no harm intended.
kind regards.
-a
···
On Fri, 24 Sep 2004, Markus wrote:
On Thu, 2004-09-23 at 09:44, Ara.T.Howard@noaa.gov wrote:
On Fri, 24 Sep 2004, Markus wrote:
On Thu, 2004-09-23 at 08:34, Ara.T.Howard@noaa.gov wrote:
since when is NUL whitespace!? defintely against POLS.
???
Since when _isn't_ NUL whitespace?
[abundant online rebuttal snipped]
Gosh. So I guess your answer to my question is "since the late
1970's or so", which, coincidentally, is most likely the last time I
checked. Back in the RS-232 paper tape and teletype days (ASCII)
whitespace was the same as non-printing, e.g. everything <= 040 and
sometimes 0177, while the EBCDIC definition was a little murkier.
*laugh* I wonder if anything else has changed in the last thirty
years?
--
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen