3 ms·
"Javascript" is slowest probably because node pushes the writes to a thread instead of printing directly from the main process like PHP. Python cheats, and it'
by megous 4y ago
"Javascript" is slowest probably because node pushes the writes to a thread instead of printing directly from the main process like PHP.
Python cheats, and it's still slow as heck even while cheating (buffers the output at 8192 chunks instead of issuing 1 byte writes).
write(1, "1", 1) loop in C pushes 6.38MiB/s on my PC. :)
- cout 4y agoWhy is it cheating to use a buffer? This is the behavior you would get in C if you used the C standard library (putc/fputc) instead of a system call (write).
- megous 4y agoBecause it doesn't answer the question "how fast individual languages write individual characters to a pipe" if in fact some languages do not. It's not language "cheating" of course. It's just OP "measuring the wrong thing".
- chupasaurus 4y agoIf you want to compare apples to apples, you can switch Python to use unbuffered stdout/stderr (via `-u` or fcntl inside the script [0]) [0]: https://stackoverflow.com/a/881751/6001364 https://stackoverflow.com/a/881751/6001364