Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
misc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
misc
Commits
0aba0aa4
Commit
0aba0aa4
authored
Mar 16, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
bfa03189
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
syspread_test.go
syspread_test.go
+57
-0
No files found.
syspread_test.go
0 → 100644
View file @
0aba0aa4
package
main
import
(
"crypto/rand"
"fmt"
"os"
"testing"
)
// 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
)
if
err
!=
nil
{
panic
(
err
)
}
if
n
!=
len
(
buf
)
{
panic
(
fmt
.
Errorf
(
"pread(%v) -> %v"
,
len
(
buf
),
n
))
}
}
// BenchmarkPread1 benchmarks pread syscall when reading 1 byte from a file on tmpfs
func
BenchmarkPread1
(
b
*
testing
.
B
)
{
// setup 4K file on a tmpfs
f
,
err
:=
os
.
Create
(
"/dev/shm/x.dat"
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
buf4K
:=
make
([]
byte
,
4096
)
_
,
err
=
rand
.
Read
(
buf4K
)
if
err
!=
nil
{
// rand promises n = len(buf) <=> err == nil
b
.
Fatal
(
err
)
}
_
,
err
=
f
.
Write
(
buf4K
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
buf1B
:=
make
([]
byte
,
1
)
// warm up
xpread
(
f
,
buf1B
,
0
)
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
xpread
(
f
,
buf1B
,
0
)
}
b
.
StopTimer
()
err
=
f
.
Close
()
if
err
!=
nil
{
b
.
Fatal
(
f
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment