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
aa9d2cb2
Commit
aa9d2cb2
authored
Nov 19, 2013
by
dvyukov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
-
parent
24be1b2b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
20 deletions
+48
-20
test/bench/perf/bench1.go
test/bench/perf/bench1.go
+7
-3
test/bench/perf/driver.go
test/bench/perf/driver.go
+41
-17
No files found.
test/bench/perf/bench1.go
View file @
aa9d2cb2
...
...
@@ -4,8 +4,12 @@ import (
"time"
)
func
Benchmark
(
N
int64
)
error
{
// 13+
func
main
()
{
PerfBenchmark
(
SleepBenchmark
)
}
func
SleepBenchmark
(
N
int64
)
(
metrics
[]
PerfMetric
,
err
error
)
{
time
.
Sleep
(
time
.
Duration
(
N
)
*
time
.
Millisecond
)
return
nil
metrics
=
append
(
metrics
,
PerfMetric
{
"foo"
,
42
})
return
}
test/bench/perf/driver.go
View file @
aa9d2cb2
...
...
@@ -3,8 +3,9 @@ package main
import
(
"flag"
"fmt"
"
os
"
"
log
"
"time"
"runtime"
)
var
(
...
...
@@ -13,45 +14,68 @@ var (
benchMem
=
flag
.
Int
(
"benchmem"
,
64
,
"approx RSS value to aim at in benchmarks, in MB"
)
)
type
Result
struct
{
type
Perf
Result
struct
{
N
int64
RunTime
time
.
Duration
Metrics
[]
PerfMetric
}
func
main
()
{
flag
.
Parse
()
var
res
Result
type
PerfMetric
struct
{
Type
string
Val
int64
}
type
BenchFunc
func
(
N
int64
)
([]
PerfMetric
,
error
)
func
PerfBenchmark
(
f
BenchFunc
)
{
if
!
flag
.
Parsed
()
{
flag
.
Parse
()
}
var
res
PerfResult
for
i
:=
0
;
i
<
*
benchNum
;
i
++
{
res1
:=
RunBenchmark
()
res1
:=
RunBenchmark
(
f
)
if
res
.
RunTime
==
0
||
res
.
RunTime
>
res1
.
RunTime
{
res
=
res1
}
}
fmt
.
Printf
(
"GOPERF-METRIC:runtime=%v
\n
"
,
int64
(
res
.
RunTime
)
/
res
.
N
)
for
_
,
m
:=
range
res
.
Metrics
{
fmt
.
Printf
(
"GOPERF-METRIC:%v=%v
\n
"
,
m
.
Type
,
m
.
Val
)
}
}
func
RunBenchmark
(
)
Result
{
var
res
Result
func
RunBenchmark
(
f
BenchFunc
)
Perf
Result
{
var
res
Perf
Result
for
ChooseN
(
&
res
)
{
res
=
RunOnce
(
res
.
N
)
log
.
Printf
(
"Benchmarking %v iterations
\n
"
,
res
.
N
)
res
=
RunOnce
(
f
,
res
.
N
)
log
.
Printf
(
"Done: %+v
\n
"
,
res
)
}
return
res
}
func
RunOnce
(
N
int64
)
Result
{
fmt
.
Printf
(
"Benchmarking %v iterations
\n
"
,
N
)
func
RunOnce
(
f
BenchFunc
,
N
int64
)
PerfResult
{
runtime
.
GC
()
mstats0
:=
new
(
runtime
.
MemStats
)
runtime
.
ReadMemStats
(
mstats0
)
res
:=
PerfResult
{
N
:
N
}
t0
:=
time
.
Now
()
err
:=
Benchmark
(
N
)
var
err
error
res
.
Metrics
,
err
=
f
(
N
)
res
.
RunTime
=
time
.
Since
(
t0
)
if
err
!=
nil
{
fmt
.
Printf
(
"Benchmark function failed: %v
\n
"
,
err
)
os
.
Exit
(
1
)
log
.
Fatalf
(
"Benchmark function failed: %v
\n
"
,
err
)
}
res
:=
Result
{
N
:
N
}
res
.
RunTime
=
time
.
Since
(
t0
)
mstats1
:=
new
(
runtime
.
MemStats
)
runtime
.
ReadMemStats
(
mstats1
)
fmt
.
Printf
(
"%+v
\n
"
,
*
mstats1
)
return
res
}
func
ChooseN
(
res
*
Result
)
bool
{
func
ChooseN
(
res
*
Perf
Result
)
bool
{
const
MaxN
=
1e12
last
:=
res
.
N
if
last
==
0
{
...
...
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