Suppose I have a very fast and infinite data source (say a socket, /dev/null or /dev/random) on Linux and I need to write such data to disk in C/C++. What’s the fastest code to accomplish that on a given hardware? fwrite(), unbuffered write(), some boost ASIO function?
Share
Well in terms of raw output speed, then you’re going to have to benchmark it, depending on the test, QoI, platform, what you are writing and a hole host of other things any of FILE, fstreams or POSIX primitives can be the fastest.
However, if you can use something like Boost asio, then you might get a percieved speed up due to it’s asynchronous nature, it can get on with the next work read whilst it’s still writing to disk.
EDIT: I would go with boost asio, it will allow you to best utilise your resources whilst waiting for inherently slow operations (File and network IO).