Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
66333b56
Commit
66333b56
authored
Jul 04, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
617ea1af
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
55 deletions
+9
-55
go/neo/t/tcpenalty.py
go/neo/t/tcpenalty.py
+2
-1
go/neo/t/tcpu.py
go/neo/t/tcpu.py
+7
-54
No files found.
go/neo/t/tcpenalty.py
View file @
66333b56
...
...
@@ -48,7 +48,8 @@ from glob import glob
from
os.path
import
basename
from
time
import
time
from
tcpu
import
B
,
readfile
from
golang.testing
import
B
from
tcpu
import
readfile
# PipeChan is `chan float` which uses OS pipe for communication.
...
...
go/neo/t/tcpu.py
View file @
66333b56
...
...
@@ -26,10 +26,10 @@ import sys
import
hashlib
import
tzodb
import
zlib
from
time
import
time
from
math
import
ceil
,
log10
from
os.path
import
dirname
from
golang
import
testing
# fmtsize formats size in human readable form
_unitv
=
"BKMGT"
# (2^10)^i represents by corresponding char suffix
def
fmtsize
(
size
):
...
...
@@ -50,66 +50,19 @@ def prettyarg(arg):
return
fmtsize
(
arg
)
# ---- 8< ---- from wendelin.core/t/py.bench
# B is benchmarking timer/request passed to benchmarks as fixture
# similar to https://golang.org/pkg/testing/#B.
class
B
:
def
__init__
(
self
):
self
.
N
=
1
# default when func does not accept `b` arg
self
.
_t_start
=
None
# t of timer started; None if timer is currently stopped
self
.
reset_timer
()
def
reset_timer
(
self
):
self
.
_t_total
=
0.
def
start_timer
(
self
):
if
self
.
_t_start
is
not
None
:
return
self
.
_t_start
=
time
()
def
stop_timer
(
self
):
if
self
.
_t_start
is
None
:
return
t
=
time
()
self
.
_t_total
+=
t
-
self
.
_t_start
self
.
_t_start
=
None
def
total_time
(
self
):
return
self
.
_t_total
# benchit runs benchf auto-adjusting whole runing time to ttarget
def
benchit
(
benchf
,
bencharg
,
ttarget
=
1.
):
b
=
B
()
b
.
N
=
0
t
=
0.
while
t
<
(
ttarget
*
0.9
):
if
b
.
N
==
0
:
b
.
N
=
1
else
:
n
=
b
.
N
*
(
ttarget
/
t
)
# exact how to adjust b.N to reach ttarget
order
=
int
(
log10
(
n
))
# n = k·10^order, k ∈ [1,10)
k
=
float
(
n
)
/
(
10
**
order
)
k
=
ceil
(
k
)
# lift up k to nearest int
b
.
N
=
int
(
k
*
10
**
order
)
# b.N = int([1,10))·10^order
b
.
reset_timer
()
b
.
start_timer
()
# benchit benchmarks benchf(bencharg)
def
benchit
(
benchf
,
bencharg
):
def
_
(
b
):
benchf
(
b
,
bencharg
)
b
.
stop_timer
()
t
=
b
.
total_time
()
r
=
testing
.
benchmark
(
_
)
benchname
=
benchf
.
__name__
if
benchname
.
startswith
(
'bench_'
):
benchname
=
benchname
[
len
(
'bench_'
):]
print
(
'Benchmark%s/py/%s %d
\
t
%.3f µs/op'
%
(
benchname
,
prettyarg
(
bencharg
),
n
,
t
*
1E6
/
n
))
(
benchname
,
prettyarg
(
bencharg
),
r
.
N
,
r
.
T
*
1E6
/
r
.
N
))
# ---- 8< ----
def
_bench_hasher
(
b
,
h
,
blksize
):
blksize
=
int
(
blksize
)
...
...
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