Buffered versus unbuffered file I/O
In this section, we are going to compare buffered and unbuffered operations while reading and writing files.
In this section, we are going to test whether the size of the buffer plays a key role in the performance of write operations. The relevant code can be found in ch14/io
. Apart from the relevant files, the directory includes a testdata
directory, which was first seen in Chapter 13, Fuzz Testing and Observability, and is used for storing data related to the testing process.
The code of table.go
is not presented here—feel free to look at it. The code of table_test.go
is the following:
package table
import (
"fmt"
"os"
"path"
"strconv"
"testing"
)
var ERR error
var countChars int
func benchmarkCreate(b *testing.B, buffer, filesize int) {
filename := path.Join(os.TempDir(), strconv.Itoa(buffer))
filename = filename + "-" + strconv.Itoa(filesize...