git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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);
}
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 8 of 21 in “git bug: rebase fatal failure”
  1. Tommy ThornMay 15, 2008
  2. Johannes SchindelinMay 16, 2008
  3. Johannes SchindelinMay 16, 2008
  4. mailsplit and mailinfo: gracefully handle NUL charactersJohannes Schindelin, May 16, 2008
  5. Avery PennarunMay 16, 2008
  6. David KastrupMay 16, 2008
  7. Johannes SchindelinMay 16, 2008
  8. Avery PennarunMay 16, 2008
  9. Johannes SchindelinMay 16, 2008
  10. Tommy ThornMay 17, 2008
  11. Johannes SchindelinMay 17, 2008
  12. Stephen R. van den BergMay 17, 2008
  13. Johannes SchindelinMay 17, 2008
  14. Junio C HamanoMay 21, 2008
  15. Johannes SchindelinMay 22, 2008
  16. Junio C HamanoMay 22, 2008
  17. Johannes SchindelinMay 23, 2008
  18. Brian FosterMay 16, 2008
  19. David KastrupMay 16, 2008
  20. Johannes SchindelinMay 16, 2008
  21. David KastrupMay 16, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.