Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
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
gevent
Commits
72b28da7
Commit
72b28da7
authored
May 05, 2012
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better bench_sleep0.py
parent
65869852
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
16 deletions
+46
-16
greentest/bench_sleep0.py
greentest/bench_sleep0.py
+46
-16
No files found.
greentest/bench_sleep0.py
View file @
72b28da7
"""Benchmarking sleep(0) performance."""
import
sys
from
time
import
time
from
gevent
import
sleep
import
os
N
=
10
def
noop
(
p
):
pass
N
=
100000
ARG
=
0
while
True
:
def
test
(
sleep
,
arg
):
start
=
time
()
user_time
,
system_time
=
os
.
times
()[:
2
]
for
_
in
xrange
(
N
):
sleep
(
0
)
user_time_x
,
system_time_x
=
os
.
times
()[:
2
]
delta
=
time
()
-
start
if
delta
>
0.2
:
break
N
*=
10
user_time_x
-=
user_time
system_time_x
-=
system_time
ms
=
1000000.
/
N
print
'N=%s delta=%s utime=%s stime=%s'
%
(
N
,
delta
,
user_time_x
,
system_time_x
)
print
(
'sleep(0): %.1f, utime: %.1f, stime: %.1f (microseconds)'
%
(
delta
*
ms
,
user_time_x
*
ms
,
system_time_x
*
ms
))
sleep
(
arg
)
return
time
()
-
start
def
bench_none
():
test
(
noop
)
def
bench_gevent
(
arg
=
0
):
import
gevent
from
gevent
import
sleep
delta
=
test
(
sleep
,
arg
)
print
(
'gevent %s (%s): sleep(%r): %.1f microseconds'
%
(
gevent
.
__version__
,
gevent
.
__file__
,
arg
,
delta
*
1000000.
/
N
))
def
bench_eventlet
(
arg
):
try
:
import
eventlet
except
ImportError
,
ex
:
sys
.
stderr
.
write
(
'Failed to import eventlet: %s
\
n
'
%
ex
)
return
from
eventlet.api
import
sleep
delta
=
test
(
sleep
,
arg
)
print
(
'eventlet %s (%s): sleep(%r): %.1f microseconds'
%
(
eventlet
.
__version__
,
eventlet
.
__file__
,
arg
,
delta
*
1000000.
/
N
))
def
main
():
global
N
for
arg
in
[
0
,
-
1
,
0.00001
]:
bench_gevent
(
arg
)
bench_eventlet
(
arg
)
N
=
1000
bench_gevent
(
0.001
)
bench_eventlet
(
0.001
)
if
__name__
==
'__main__'
:
main
()
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