Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)

X

xhoster

Martijn Lievaart said:
No I did not try it.

Or, apparently, understand it.
I don't have to. this C implementation stops at the
first null character.

Sure, it stops at the first null in s2. But not the first null in s1.
Well, the *inner* loop does stop at the first null in s1, but then it
restarts. And restarts again. And again. It doesn't stop for good until it
hits the "first" (and last) null in s2.
Why do you think it'll behave otherwise?

Because I wrote it that way on purpose, and because I tested it.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
M

Michele Dondi

I think that both Usenet and Perlmonks are interactive media, and both
are best served by an occasional post saying something like "there's
an interesting conversation going on about $subject over on
Perlmonks." People who want Perlmonks know where to find it, by and

Good point. I still beg to differ in that experimental evidence shows
that when giving just a link people tend not to answer: perhaps simply
warnock applies, but generally there's not evidence of posting in the
other media even anonymously either. Instead in this very thread you
can see that some people *did* answer taking advantage of their own
newsreaders' facilities. Some times even knowledgeable and smart
people must be "brought by hand".

Anyway those above are just a few random observations from me and I
won't take them as an excuse to keep doing so: it was my intent to
provide a *service* to the community, albeit admittedly a "minor" one.
But if it's not received as such, if it's annoying instead, then I'm
in no way investing my time and resources in such an activity?
large, and it's not as if clpm is hurting for traffic.

What do you mean? Too much traffic or too little? Personally I'm now
ignoring most threads. I got tired of posts about how to "split a
line" or validate some params for webby stuff... There's very little
*interesting* traffic. But maybe that's just me.
I don't think "Post it, and if people find it unwelcome they can
filter it out" is a polite strategy to pursue. But I'm not the

I hope you will agree that it was an attempt at politeness. But as I
wrote, I'm not insisting anyway.


Michele
 
M

Michele Dondi

i am not there because of the web api (why no news/email gateway?) and ^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^

because i have never was into the monk culture. and yes i know plenty of

I would dream of such a beast.


Michele
 
M

Michele Dondi

I agree with them. It's a lame thing to do, reposting other people's
stuff (heh, from the guy who runs the perlfaq server :).

Posting your own stuff is fine, or your own thoughts on someone else's
ideas is fine, but just reposting something with no transformative
effect is a pillar of copyright infringement, and it's rude to the
author.

As I wrote in reply to Charlton, I'm stopping anyway, but I can't see
how so: are texts posted to public fora and newsgroups supposed to
count as copyrighted material? Do you see a problem of ethic nature?
(Especially taking into account the inclusion of proper attributions
and/*or* a link to the original post?)

Incidentally, a rewriting of an entire thread, summing up the
interesting bits in an organized manner and the rougher practice of
bare copying -but possibly for some formatting- are commonly separated
simply by a thing called *lack of time*.


Michele
 
M

Michele Dondi

It serves as scaffolding to persons who are newer to the syntax. As far as
I'm concerned, I solved the posed problem instantaneously, because I never
got the question within this 24-hr. period that ends in the middle of the
day, Italian time.

Of course the question was practical in nature, and the 24 hours limit
applied to that side of it. Though it was and still is interesting as
of itself. All this, of course, rigorously IMHO.


Michele
 
M

Michele Dondi

How about posting original content of which you are the author? Talking

Sometimes I do. Didn't I?
about a problem that you think is interesting, expounding on it, and so
on would be a lot better.

Of course. Just as obviously I'm not that smart. And while *creating*
knowledge is a vastly superior activity, *spreading* it shouldn't be
that bad either.
Otherwise, let the original authors decide where to post their own work.

Original authors often post just to one place out of habit and
convenience. Some readers just stick to reading in one place out of
habit and convenience. Some of the latter ones will miss forever some
interesting bits from some of the former ones sometime. I was trying
to contribute a tiny piece of help to remedy this situation; I was
probably wrong in my judgement, and I will refrain from doing so,
especially in one direction that is.


Michele
 
M

Michele Dondi

another crazy idea is to use something like $s1 =~ /(\0)/g to find and
grab all the zero spots. then use @+ (or @- whichever works right) as a

That is what avar did.

http://perlmonks.org/?node_id=638563
list of indexes to substr out of $s2 and into $s1. that line can be done
in a for modifier. something like this (very untested):

@zeroes = $s1 =~ /(\0)/g ;
substr( $s1, $_, 1, substr( $s2, $_, 1 ) ) for @- ;

He did that in a /e:

sub subst
{
my ($s1, $s2) = @_;

my $s3 = $s1;

{
use bytes;
$s3 =~ s/(\0)/substr $s2, $+[0]-1, 1/eg;
}

$s3;
}
one last idea is maybe bit::vector has such a feature or methods to
build one. it is very fast and optimized for this sort of thing.

Somebody else suggested that. (I'm not really sure whether before or
after you.) But no actual code was provided or tested.


Michele
 
C

Charlton Wilbur

MD> What do you mean? Too much traffic or too little? Personally
MD> I'm now ignoring most threads. I got tired of posts about how
MD> to "split a line" or validate some params for webby
MD> stuff... There's very little *interesting* traffic. But maybe
MD> that's just me.

I mean that clpm already has a great deal of traffic.

Much of it is admittely not interesting, but knowing that there's a
moderately to very interesting conversation going on in a place where
the interface sets my teeth on edge does not improve matters, and
neither does having selected posts from that conversation relayed here.

MD> I hope you will agree that it was an attempt at
MD> politeness. But as I wrote, I'm not insisting anyway.

No, I think you were attempting to improve the signal-to-noise ratio
of clpm, and that's to be commended. I just don't think you actually
succeded, because relaying signal from another place doesn't really help.

Charlton
 
M

Michele Dondi

The problem with moritz is that it compares index(...) to >0, rather than
either >-1 or >=0, for success, so it fails when the first char is \000. I
fixed that, and changed to 4-argument substr.

You're right, but the error with the index was already corrected in an
update.
For my own effort, I perhaps cheated by using Inline C, and depending on
the C representations of both strings being null terminated.

There's another pair of C solutions:

http://perlmonks.org/?node_id=638724

(I'm not sure but I suppose that depending on the C representations of
both strings being null terminated is not appropriate *for this
particular problem*.)


Michele
 
M

Michele Dondi

Wade Ward
(e-mail address removed)
'If they took all the "And it came to pass's" out
of the Book of Mormon, it would be a pamphlet.'
--Mark Twain
Hi. This is the qmail-send program at
smtpauth04.prod.mesa1.secureserver.net.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

<[email protected]>:
213.205.33.35 does not like recipient.
Remote host said: 552 RCPT TO:<[email protected]> Mailbox disk quota
exceeded

I gave you my *real* email address and my jabber contact in another
post. I'm writing to you in point of "test".


Michele
 
M

Michele Dondi

// i am not there because of the web api (why no news/email gateway?) and

A news/email gateway would give you the worst of two worlds, wouldn't it?
You'll get messages on usenet that don't quote context, and you'll get
webpages that contain the same text over and over again.

I *think* that it could be feasible, abeit hard, to automatically go a
long way in the direction of correcting this. Nothing 100% bulletproof
of course, and still requiring author's interventions. It would be
different if there were a (even more) restricted set of tags for the
web interface and a standard two way translation to pure text media.
// because i have never was into the monk culture. and yes i know plenty of
// people there but i have seen too many idiots. there are idiots on usenet
// too but emacs makes it easier to ignore them.


Not to mention that on Perlmonks they don't care at all whether your
answer is correct or not. As long as you pat each other on the back,
telling how wonderful all the monks are, all is fine.

I rather not have the Perlmonk culture infiltrating on Usenet.

I don't share *entirely* Abigail's view, but I admit there's some
truth in it.


Michele
 
M

Michele Dondi

(I'm not sure but I suppose that depending on the C representations of
both strings being null terminated is not appropriate *for this
particular problem*.)

Please ignore this. I see it was addressed in another part of this
thread.


Michele
 
U

Uri Guttman

A> _
A> Uri Guttman ([email protected]) wrote on VCXXVI September MCMXCIII in
A> <URL:

A> // because i have never was into the monk culture. and yes i know plenty of
A> // people there but i have seen too many idiots. there are idiots
A> on usenet
A> // too but emacs makes it easier to ignore them.

A> Not to mention that on Perlmonks they don't care at all whether your
A> answer is correct or not. As long as you pat each other on the back,
A> telling how wonderful all the monks are, all is fine.

A> I rather not have the Perlmonk culture infiltrating on Usenet.

you expressed my dislike of their culture perfectly. they are more
cliquish that i want to deal with. when i did post some there a while
back, monks who know from nothing ragged my comments. i don't need to
fight twits who don't understand what i am saying. i don't want nor need
to climb a social (not technical) ranking system. that and the web
interface makes it a no brainer for me to ignore the monks.

uri
 
B

brian d foy

As I wrote in reply to Charlton, I'm stopping anyway, but I can't see
how so: are texts posted to public fora and newsgroups supposed to
count as copyrighted material?

Well, depending on the source country and local laws, yes, authorship
is generally automatically counted as copyrighted material just by the
act of creation. The author publishes it in a certain way, such as on
Perlmonks. That doesn't necessarily mean he wants it published in some
other way.

See "transformative effect" discussions about copyright, which I
mentioned earlier.
Do you see a problem of ethic nature?

Well, I do, but that doesn't mean that everyone does. I certainly think
it is rude to the author to simply repost an entire post.
(Especially taking into account the inclusion of proper attributions
and/*or* a link to the original post?)

I don't think you gave proper attribution. You linked to the original
post, but you did not identify the original author in the clpm message.
 
M

Michele Dondi

I don't think you gave proper attribution. You linked to the original
post, but you did not identify the original author in the clpm message.

Well, re this particular point I was about to answer you in the
use.perl journal, and I will probably do anyway. You're of course
right and it would be poinltless to claim that I did. (BTW: did you
notice how I emphasized "or" above?) Still I hope you will agree that

1. in all the other posts "of the same nature" I did include the name
or the nick of the original author;

2. even in this particular one I specified that I'm not the author of
the original post, and giving the link also gives one the means to
check who the latter actually is.


Michele
 
J

jgraber

(my $s1m = $s1) =~ tr/\000-\377/\377\000/;
$s1 |= ($s2 & $s1m);

Converted to a subroutine suitable for previous benchmark program

sub trandor_ref{
my ($s1ref, $s2ref) = @_;
(my $s1m = $$s1ref) =~ tr/\000-\377/\377\000/;
$$s1ref |= ($$s2 & $s1m);
}


Benchmark results:
Rate avar2 moritz trandor_ref
avar2 1244/s -- -26% -95%
moritz 1673/s 34% -- -93%
trandor_ref 22904/s 1741% 1269% --

Another example of Perl writing better C than I do.

If perl6 had another version of tr/// that returned the resulting
string instead of the number of matches, this could be a 1-liner.
 
T

Tad McClellan

brian d foy said:
That doesn't necessarily mean he wants it published in some
other way.

See "transformative effect" discussions about copyright, which I
mentioned earlier.


Well, I do, but that doesn't mean that everyone does. I certainly think
it is rude to the author to simply repost an entire post.


I become incensed with so-called "forums" such as thescripts.com
where my posts here are disguised as if they were posts made there
(by virtue of them labelling me a "Guest", I am NOT their guest,
never was, never will be).

I make killfile entries for the entire domain whenever I come across
such abusers of our community.


Should you happen to "cross pollinate" someone who strongly
opposes the forum they did not post to, it might lead to similar bad
feelings...
 
X

xhoster

Converted to a subroutine suitable for previous benchmark program

sub trandor_ref{
my ($s1ref, $s2ref) = @_;
(my $s1m = $$s1ref) =~ tr/\000-\377/\377\000/;
$$s1ref |= ($$s2 & $s1m);
}

Alas, I suspect it is giving you the wrong answer. $s2 is not
declared in that sub, so either you are using the package variable, or are
accidentally using an $s2 declared elsewhere.

Benchmark results:
Rate avar2 moritz trandor_ref
avar2 1244/s -- -26% -95%
moritz 1673/s 34% -- -93%
trandor_ref 22904/s 1741% 1269% --


When I fix the $$s2 to $$s2ref, it gets a lot slower, but does
give the right answer. If I change the tr to be tr/\000/\377/
it still seems to give the right answer, but is now a lot faster
(The fastest pure Perl implementation I've seen yet.)

avar2 1378/s
trandor_ref 1884/s
moritz 1889/s
joel 2765/s
inline_c 8266/s

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top