Re: [PATCH] mailsplit and mailinfo: gracefully handle NUL characters
- From
Avery Pennarun <apenwarr@gmail.com>
- Date
- May 16, 2008, 14:56 UTC
- Message-ID
- <32541b130805160756h5a8fc4d7x313f9bfde4760568@mail.gmail.com>
- In-Reply-To
- <alpine.DEB.1.00.0805161529390.30431@racer>
On 5/16/08, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 5 quoted lines
> Hmpf. I hoped to get more definitive information here. Especially given > that fgetc() is nothing more than a glorified fread() into a buffer, and > then access the buffer. > > Well, at least you kind of pointed me to the _unlocked() function family.
Point taken.
/tmp $ for d in test1 test2 test3 test3u; do echo -n "$d: "; /usr/bin/time ./$d </dev/zero; done test1: 0.09user 0.05system 0:00.14elapsed 94%CPU test2: 2.50user 0.05system 0:02.54elapsed 100%CPU test3: 2.48user 0.06system 0:02.53elapsed 100%CPU test3u: 1.05user 0.05system 0:01.10elapsed 99%CPU
fread is about 18x faster than fgetc(). getc() is the same speed as fgetc(). getc_unlocked() is definitely faster than getc, but still at least 7x slower than fread().
And if you think *that* sucks, you should try "c << cin" in C++ :)
Source code below.
Have fun,
Avery
=== test1.c === #include <stdio.h>
int main()
{
char buf[1024];
int i;
for (i = 0; i < 102400; i++)
fread(buf, 1, sizeof(buf), stdin);
}=== test2.c === #include <stdio.h>
int main()
{
int i;
for (i = 0; i < 1024*102400; i++)
fgetc(stdin);
}=== test3.c === #include <stdio.h>
int main()
{
int i;
for (i = 0; i < 1024*102400; i++)
getc(stdin);
}=== test3u.c === #include <stdio.h>
int main()
{
int i;
for (i = 0; i < 1024*102400; i++)
getc_unlocked(stdin);
}