benchmark-mmap

command module
v0.0.0-...-6532f9f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

benchmark-mmap

Benchmark Go mmap implementations

The golang.org/x/sys/unix package

Platform-specific: works on Linux and Unix variants, but not Windows.

The github.com/edsrzf/mmap-go package

One of several cross-platform mmap wrapper packages that I found.

It has the cleanest API of the ones I found.

Under the hood it uses mmap on *Nix systems and on Windows the CreateFileMapping and MapViewOfFile Windows API methods.

It exposes a []byte, which matches the API of unix.Mmap, and decorates that with methods to manipulate it, like Read() and Close().

os.File.ReadAt()

which isn't really memory mapping, but it is randomly reading parts of a file.

It was/is included as a non-*nix "memory map" option in the zoekt project, which is why it's included here.

It's so much slower than memory mapping, it doesn't really deserve consideration.

Notes

The benchmark setup involves creating a 1GB-sized file in the current working directory filled with random bytes.

Each benchmark consists of opening/mapping that file, reading 20,000,000 50k chunks at random locations, and then unmapping/closing the file.

The cleanup at the end of the benchmarks deletes the 1GB file.

To run the benchmarks

go test -bench .

You can filter the benchmarks by passing regular expressions to -bench instead of the dot (.). To avoid the slooooow file-based "mapping" benchmark, use the regular expression '.*(Unix|Mmap)'

Example of using Docker for benchmarking on other platforms

docker run --rm --volume $(pwd):/src --volume ${GOPATH:-${HOME}/go}:/go --workdir /src --interactive golang <<<"go test -bench ."

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL