Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
go
Commits
11384eec
Commit
11384eec
authored
Dec 04, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testing: compute MB/s in benchmarks
R=r
https://golang.org/cl/166060
parent
4ed57173
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
1 deletion
+11
-1
src/pkg/testing/benchmark.go
src/pkg/testing/benchmark.go
+11
-1
No files found.
src/pkg/testing/benchmark.go
View file @
11384eec
...
...
@@ -26,6 +26,7 @@ type B struct {
N
int
;
benchmark
Benchmark
;
ns
int64
;
bytes
int64
;
start
int64
;
}
...
...
@@ -50,6 +51,10 @@ func (b *B) ResetTimer() {
b
.
ns
=
0
;
}
// SetBytes records the number of bytes processed in a single operation.
// If this is called, the benchmark will report ns/op and MB/s.
func
(
b
*
B
)
SetBytes
(
n
int64
)
{
b
.
bytes
=
n
}
func
(
b
*
B
)
nsPerOp
()
int64
{
if
b
.
N
<=
0
{
return
0
...
...
@@ -125,7 +130,12 @@ func (b *B) run() {
n
=
roundUp
(
n
);
b
.
runN
(
n
);
}
fmt
.
Printf
(
"%s
\t
%d
\t
%10d ns/op
\n
"
,
b
.
benchmark
.
Name
,
b
.
N
,
b
.
nsPerOp
());
ns
:=
b
.
nsPerOp
();
mb
:=
""
;
if
ns
>
0
&&
b
.
bytes
>
0
{
mb
=
fmt
.
Sprintf
(
"
\t
%7.2f MB/s"
,
(
float64
(
b
.
bytes
)
/
1e6
)
/
(
float64
(
ns
)
/
1e9
))
}
fmt
.
Printf
(
"%s
\t
%8d
\t
%10d ns/op%s
\n
"
,
b
.
benchmark
.
Name
,
b
.
N
,
b
.
nsPerOp
(),
mb
);
}
// An internal function but exported because it is cross-package; part of the implementation
...
...
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