Commit 8bc6d19a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3ff8da1e
This diff is collapsed.
......@@ -6,6 +6,7 @@ import (
"log"
"os"
"runtime/pprof"
"syscall"
"time"
)
......@@ -13,8 +14,8 @@ import (
const Niter = 1000000
// xpread is pread(2) but aborts on an error or when fewer bytes was read
func xpread(f *os.File, buf []byte, offset int64) {
n, err := f.ReadAt(buf, offset)
func xpread(fd int, buf []byte, offset int64) {
n, err := syscall.Pread(fd, buf, offset)
if err != nil {
panic(err)
}
......@@ -23,6 +24,18 @@ func xpread(f *os.File, buf []byte, offset int64) {
}
}
// xreadat is ReadAt but aborts on an error or when fewer bytes was read
func xreadat(f *os.File, buf []byte, offset int64) {
n, err := f.ReadAt(buf, offset)
if err != nil {
panic(err)
}
if n != len(buf) {
panic(fmt.Errorf("readat(%v) -> %v", len(buf), n))
}
}
const BufSize = 4096
var buf [BufSize]byte
......@@ -50,17 +63,18 @@ func main() {
if err != nil {
log.Fatal(err)
}
fd := int(f.Fd())
for size := 0; size <= BufSize; {
sbuf := buf[:size]
// warmup
xpread(f, sbuf, /*offset=*/0)
xpread(fd, sbuf, /*offset=*/0)
Tstart := time.Now()
for i := 0; i < Niter; i++ {
xpread(f, sbuf, /*offset=*/0)
xpread(fd, sbuf, /*offset=*/0)
}
Tend := time.Now()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment