memcmp() is slow?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi,
I have seen a patch that replaces memcmp() with a few comparison statements. The log for the change says that memcmp() is slow.
Why is it? Is it just due to the overhead of calling a function and going through the memory in a loop? Or are there other issues I am not aware of.
Ragards,
Maciej
Below is the mention patch:
trunk/patch-o-matic-ng/nf_conntrack/linux-2.6/include/linux/netfilter/nf_conntrack_tuple.h
2005-01-22 19:05:07 UTC (rev 3607)
@@ -142,19 +142,25 @@
static inline int nf_ct_tuple_src_equal(const struct nf_conntrack_tuple *t1,
const struct nf_conntrack_tuple *t2)
{
- return (!memcmp(t1->src.u3.all, t2->src.u3.all, sizeof(t1->src.u3.all)))
- && (t1->src.u.all == t2->src.u.all) - && (t1->src.l3num == t2->src.l3num) - && (t1->dst.protonum == t2->dst.protonum); + return (t1->>src.u3.all[0] == t2->src.u3.all[0] && + t1->>src.u3.all[1] == t2->src.u3.all[1] && + t1->>src.u3.all[2] == t2->src.u3.all[2] && + t1->>src.u3.all[3] == t2->src.u3.all[3] && + t1->>src.u.all == t2->src.u.all && + t1->>src.l3num == t2->src.l3num && + t1->>dst.protonum == t2->dst.protonum);
Quoted 1 line
}
Quoted 4 lines · On Sat, 22 Jan 2005 21:31:52 +0100 Maciej Soltysiak <[email protected]>…
I have seen a patch that replaces
memcmp()with a few comparison statements. The log for the change says thatmemcmp()is slow.Why is it?
This is a platform specific question, as memcmp() is implemented differently on each architecture. So tell us what you're test was run on. :)
Hello David,
Quoted 3 lines · you
This is a platform specific question, as
memcmp()is implemented differently on each architecture. So tell us what you're test was run on. :)
Well, it was yoshfuji's patch that suggested the change explaining that memcmp() is slow.
If joshfuji suggests a change like that, I think he is pretty sure that for all archs' memcmp() of 4 integers is slower than simply comparing them.
Anyway I was not aware of such a multiplicity of memcmp() and friends implementations for different archs. Good to know :-)
Regards,
Maciej
Hi,
From: Maciej Soltysiak <[email protected]>
Date: Sun, 23 Jan 2005 10:57:09 +0100
Quoted 8 lines
Hello David,
Quoted 3 lines · you
This is a platform specific question, as
memcmp()is implemented differently on each architecture. So tell us what you're test was run on. :)
Quoted 6 lines
Well, it was yoshfuji's patch that suggested the change explaining that
memcmp()is slow.If joshfuji suggests a change like that, I think he is pretty sure that for all archs'
memcmp()of 4 integers is slower than simply comparing them.
Yoshifuji and I think the reason is that memcmp() distinguishes 3 cases and this code needs to distinguish only 2 cases (equal or not).
I run this code on Pentium M 1.1GHz. But I'm not sure it's true on other archs. Should I revert it ?
-----------------------------------------------------------------
Yasuyuki KOZAKAI @ USAGI Project <[email protected]>