LINUX.ORG.RU

История изменений

Исправление thegoldone, (текущая версия) :

Это читы.

// cat test_raw.cpp
#include <unistd.h>

#define MSG "num: 42.42\n"

int
main ()
{
  for (int i = 0; i < 10000000; ++i)
    {
      write (STDOUT_FILENO, MSG, sizeof (MSG));
    }
  return 0;
}
$ time ./test_iostream > /dev/null

real    0m1,815s
user    0m1,809s
sys     0m0,003s
$ time ./test_printf > /dev/null

real    0m1,066s
user    0m1,058s
sys     0m0,007s
$ time ./test_raw > /dev/null

real    0m1,598s
user    0m0,437s
sys     0m1,160s

В итоге printf быстрее чем write. Читы. Попробуйте g++ --no-printf-cheats.

Исходная версия thegoldone, :

Это читы.

// cat test_raw.cpp
#include <unistd.h>

#define MSG "num: 42.42\n"

int
main ()
{
  for (int i = 0; i < 10000000; ++i)
    {
      write (STDOUT_FILENO, MSG, sizeof (MSG));
    }
  return 0;
}
$ time ./test_iostream > /dev/null

real    0m1,815s
user    0m1,809s
sys     0m0,003s
$ time ./test_printf > /dev/null

real    0m1,066s
user    0m1,058s
sys     0m0,007s
$ time ./test_raw > /dev/null

real    0m1,598s
user    0m0,437s
sys     0m1,160s

В итоге printf быстрее чем write. Читы. Попробуйте g++ -no-printf-cheats.