A
av
what is f00f_bug? it seems my pentium pc has it
what is f00f_bug? it seems my pentium pc has it
jacob navia said:GREAT DAVE!!!
1) You are a genius.
You can even correct warnings that you yourself
provoked! Impressing.
2) I explicitely disabled optimizations. Apparently you don't. Then,
you got waht you want. ASTOUNDING.
1) thompson asks me if I have data for any difference between strchr and
memchr.
2) I take the effort to do it. I provide the data.
3) You start by correcting pedantic warnings. Sure being a pedant like
your mentors you stop there.
jacob navia said:Instead of strcat Strcat, etc. That's why operator overloading comes
handy since it allows ...
root@ubuntu:/tmp# gcc tmemchr.cI started by making sure I was working with a correct C program.
If you consider this inappropriate, you're posting to the wrong newsgroup.
dave
[1] The obvious comment about frames of reference is Left As An Exercise
For The Reader.
C does not have operator (or any other type of) overloading. You appear
to have, yet again, gotten lost on your way to comp.lang.c++.
<OT> C++ even has a standard "string" object, which does all of the nice
things you're advocating here, and is typically implemented with counted
strings. </OT>
S
jacob navia said:Dave Vandervies a écrit :
[snip]root@ubuntu:/tmp# gcc tmemchr.cI started by making sure I was working with a correct C program.
If you consider this inappropriate, you're posting to the wrong newsgroup.
dave
[1] The obvious comment about frames of reference is Left As An
Exercise
For The Reader.
root@ubuntu:/tmp# ./a.out
Time for strchr=51
Time for memchr=27 [snip]
In any case it proves my point
strchr is slower by more than 30 % compared to memchr under libc/linux
jacob navia said:I have implemented operator overloading in the lcc-win32
coimpiler system. I think it is an improvement to C, without
incurring with all the associated costs of C++.
Ok, but apart from code that is explicitly non-reentrant (because it
allocates data with limited scoop in a statical fashion), C code will be
reentrant, meaning that any function can call any function, including
itself, without having the functions' "instances" conflicting with each
other...
jacob navia said:root@ubuntu:/tmp# gcc tmemchr.c
root@ubuntu:/tmp# ./a.out
Time for strchr=51
Time for memchr=27
[...]
How I did that?
This is Left As An Exercise For The Reader.
root@ubuntu:/tmp# ./a.out
Time for strchr=51
Time for memchr=27 [snip]In any case it proves my point
strchr is slower by more than 30 % compared to memchr under libc/linux
On an x86 platform.
I asked whether you had tested it on multiple
platforms. Optimizations that work only on x86 systems are only
slightly interesting.
root@ubuntu:/tmp# gcc tmemchr.c
root@ubuntu:/tmp# ./a.out
Time for strchr=51
Time for memchr=27
[...]
How I did that?
This is Left As An Exercise For The Reader.
I don't think I'll bother. Since you don't seem to be inclined to be
cooperative, it's Highly Unlikely to be worth my time and energy to
figure out why you're claiming results that can't be replicated here.
dave
Keith Thompson said:root@ubuntu:/tmp# ./a.out
Time for strchr=51
Time for memchr=27
[snip]
In any case it proves my point
strchr is slower by more than 30 % compared to memchr under libc/linux
On an x86 platform.
On his particular x86 system. I couldn't replicate his results on any
of the three x86 systems I tried it on (all run the entire test program
in no more than a few tenths of a second), and nobody else seems to have
though it was worth trying it and posting the results. (On the slowest
of the bunch (the only I tried to find an actual difference on rather
than just re-running the test that navia posted), four billion calls to
either function took a little bit over 200 seconds, with the differences
between them smaller than the error bound on the measurement.)
I asked whether you had tested it on multiple
platforms. Optimizations that work only on x86 systems are only
slightly interesting.
...and optimizations that work only on the x86 system used by the person
claiming the optimization is useful are even less interesting.
dave
I have sent you elsethread the corrected program.
Since now gcc optimizes even when it is not told
to do that, you have to trick it into generating code
for the program you wrote, not for the program gcc
think you should have written.
#include <stdio.h>
#include <time.h>
#include <string.h>
#define MAXITER 10000000
int main(void){
char s[4096];
int i,c=0;
time_t t,tStrchr,tMemchr;
for (i=0; i<sizeof(s)-1;i++) {
s = 'a';
}
s[sizeof(s)-1] = 0;
t = time(NULL);
for (i=0; i<MAXITER;i++) {
if (strchr(s,'1'))
if( memchr(s,'1',sizeof(s)))}
tStrchr= time(NULL) - t;
printf("Time for strchr=%d\n",tStrchr);
t = time(NULL);
for (i=0; i<MAXITER;i++) {
In any case it proves my point
strchr is slower by more than 30 % compared to memchr under libc/linux
<snip>#ifdef MEMCHR
memchr(s, '1', sizeof s)
#else
strchr(s, '1')
#endif
jacob navia wrote:
In any case it proves my point
strchr is slower by more than 30 % compared to memchr under libc/linux
dougal(~/navia) cat chr.c
#include <stdio.h>
#include <string.h>
#define MAXITER 100000000
int main(void)
{
char s[4096];
int i;
memset(&s, 'a', sizeof(s) - 1);
s[sizeof(s)-1] = 0;
for (i = 0; i < MAXITER; i++)
{
#ifdef MEMCHR
memchr(s, '1', sizeof s)
#else
strchr(s, '1')
#endif
}
return 0;
}
dougal(~/navia) gcc -O0 chr.c -o strchr
dougal(~/navia) time ./strchr
real 0m1.403s
user 0m0.990s
sys 0m0.040s
dougal(~/navia) time ./strchr
real 0m1.743s
user 0m1.000s
sys 0m0.050s
dougal(~/navia) time ./strchr
real 0m1.212s
user 0m1.000s
sys 0m0.050s
dougal(~/navia) gcc -O0 chr.c -DMEMCHR -o memchr
dougal(~/navia) time ./memchr
real 0m1.874s
user 0m1.010s
sys 0m0.020s
dougal(~/navia) time ./memchr
real 0m1.485s
user 0m1.030s
sys 0m0.030s
dougal(~/navia) time ./memchr
real 0m1.282s
user 0m0.990s
sys 0m0.020s
I can see no clear pattern in the performance of the two functions, and
believe that your claim is unsubstantiated.
/proc/cpuinfo says that the processor this was run on was a 735Hz VIA
Ezra (x86) processor, with the flags "fpu de tsc msr cx8 mtrr pge mmx
3dnow", and a 64KB cache.
Andrew Sidwell
Dave Vandervies a écrit :
[snip]root@ubuntu:/tmp# gcc tmemchr.cI started by making sure I was working with a correct C program.
If you consider this inappropriate, you're posting to the wrong newsgroup.
dave
[1] The obvious comment about frames of reference is Left As An Exercise
For The Reader.
root@ubuntu:/tmp# ./a.out
Time for strchr=51
Time for memchr=27
root@ubuntu:/tmp# uname -a
Linux ubuntu 2.6.12-10-386 #1 Fri Sep 15 16:31:49 UTC 2006 i686 GNU/Linux [snip]
In any case it proves my point
strchr is slower by more than 30 % compared to memchr under libc/linux
Dave Vandervies a écrit :Keith Thompson said:root@ubuntu:/tmp# ./a.out
Time for strchr=51
Time for memchr=27
[snip]
In any case it proves my point
strchr is slower by more than 30 % compared to memchr under libc/linux
On an x86 platform.
On his particular x86 system. I couldn't replicate his results on any
of the three x86 systems I tried it on (all run the entire test program
in no more than a few tenths of a second), and nobody else seems to have
though it was worth trying it and posting the results. (On the slowest
of the bunch (the only I tried to find an actual difference on rather
than just re-running the test that navia posted), four billion calls to
either function took a little bit over 200 seconds, with the differences
between them smaller than the error bound on the measurement.)
I asked whether you had tested it on multiple
platforms. Optimizations that work only on x86 systems are only
slightly interesting.
...and optimizations that work only on the x86 system used by the person
claiming the optimization is useful are even less interesting.
dave
I have sent you elsethread the corrected program.
Since now gcc optimizes even when it is not told
to do that, you have to trick it into generating code
for the program you wrote, not for the program gcc
think you should have written.
#include <stdio.h>
#include <time.h>
#include <string.h>
#define MAXITER 10000000
int main(void){
char s[4096];
int i;
time_t t,tStrchr,tMemchr;
for (i=0; i<sizeof(s)-1;i++) {
s = 'a';
}
s[sizeof(s)-1] = 0;
t = time(NULL);
for (i=0; i<MAXITER;i++) {
strchr(s,'1');
}
tStrchr= time(NULL) - t;
printf("Time for strchr=%d\n",tStrchr);
t = time(NULL);
for (i=0; i<MAXITER;i++) {
memchr(s,'1',sizeof(s));
}
tMemchr=time(NULL)-t;
printf("Time for memchr=%d\n",tMemchr);
}
DAMM!!!!!
I sent you the wrong one.
Here is the one with the necessary corrections for gcc.
1) new variable c, is incremented at
each function call. Then the compiler
cab't optimize the call away.
To avoid that the variable is discarded
main returns that value
jacob navia a écrit :I have sent you elsethread the corrected program.
Since now gcc optimizes even when it is not told
to do that, you have to trick it into generating code
for the program you wrote, not for the program gcc
think you should have written.
#include <stdio.h>
#include <time.h>
#include <string.h>
#define MAXITER 10000000
int main(void){
char s[4096];
int i,c=0;
time_t t,tStrchr,tMemchr;
for (i=0; i<sizeof(s)-1;i++) {
s = 'a';
}
s[sizeof(s)-1] = 0;
t = time(NULL);
for (i=0; i<MAXITER;i++) {
if (strchr(s,'1')) c++;
;
}
tStrchr= time(NULL) - t;
printf("Time for strchr=%d\n",tStrchr);
t = time(NULL);
for (i=0; i<MAXITER;i++) {
if( memchr(s,'1',sizeof(s)))
c++;}
tMemchr=time(NULL)-t;
printf("Time for memchr=%d\n",tMemchr); return c;
}
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.