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
3d48b813
Commit
3d48b813
authored
Aug 13, 2009
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/bench_spawn.py: add geventraw and geventpool options
parent
a92e7730
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
36 deletions
+38
-36
examples/bench_spawn.py
examples/bench_spawn.py
+38
-36
No files found.
examples/bench_spawn.py
View file @
3d48b813
...
...
@@ -7,9 +7,10 @@ N = 20000
counter
=
0
def
incr
(
**
kwargs
):
def
incr
(
sleep
,
**
kwargs
):
global
counter
counter
+=
1
sleep
(
0
)
if
not
sys
.
argv
[
1
:]:
sys
.
exit
(
'USAGE: python bench_spawn.py none|gevent|eventlet [eventlet_hub]'
)
...
...
@@ -21,10 +22,26 @@ if sys.argv[-1]=='kwargs':
kwargs
=
{
'foo'
:
1
,
'bar'
:
'hello'
}
del
sys
.
argv
[
-
1
]
def
noop
(
p
):
pass
def
test
(
spawn
,
sleep
):
start
=
time
()
for
_
in
xrange
(
N
):
spawn
(
incr
,
sleep
,
**
kwargs
)
delta
=
time
()
-
start
print
'spawning: %.1f microseconds per greenlet'
%
(
delta
*
1000000.0
/
N
)
assert
counter
==
0
,
counter
start
=
time
()
sleep
(
0
)
delta
=
time
()
-
start
assert
counter
==
N
,
(
counter
,
N
)
print
'sleep(0): %.1f microseconds per greenlet'
%
(
delta
*
1000000.0
/
N
)
if
sys
.
argv
[
1
]
==
'none'
:
start
=
time
()
for
_
in
xrange
(
N
):
incr
(
**
kwargs
)
incr
(
noop
,
**
kwargs
)
delta
=
time
()
-
start
assert
counter
==
N
,
(
counter
,
N
)
print
'%.2f microseconds'
%
(
delta
*
1000000.0
/
N
)
...
...
@@ -32,49 +49,34 @@ elif sys.argv[1]=='gevent':
import
gevent
print
gevent
.
__file__
from
gevent
import
spawn
,
sleep
test
(
spawn
,
sleep
)
elif
sys
.
argv
[
1
]
==
'geventraw'
:
import
gevent
print
gevent
.
__file__
from
gevent
import
sleep
from
gevent.rawgreenlet
import
spawn
test
(
spawn
,
sleep
)
elif
sys
.
argv
[
1
]
==
'geventpool'
:
import
gevent
print
gevent
.
__file__
from
gevent
import
sleep
from
gevent.pool
import
Pool
p
=
Pool
()
test
(
p
.
spawn
,
sleep
)
start
=
time
()
for
_
in
xrange
(
N
):
spawn
(
incr
,
**
kwargs
)
delta
=
time
()
-
start
print
'spawning: %d microseconds'
%
(
delta
*
1000000.0
/
N
)
assert
counter
==
0
,
counter
start
=
time
()
sleep
(
0
)
p
.
join
()
delta
=
time
()
-
start
assert
counter
==
N
,
(
counter
,
N
)
print
'switching: %d microseconds'
%
(
delta
*
1000000.0
/
N
)
print
'joining: %.1f microseconds per greenlet'
%
(
delta
*
1000000.0
/
N
)
elif
sys
.
argv
[
1
]
==
'eventlet'
:
import
eventlet
print
eventlet
.
__file__
from
eventlet.api
import
spawn
,
sleep
,
use_hub
if
sys
.
argv
[
2
:]:
use_hub
(
sys
.
argv
[
2
])
start
=
time
()
for
_
in
xrange
(
N
):
spawn
(
incr
,
**
kwargs
)
delta
=
time
()
-
start
print
'spawning: %d microseconds'
%
(
delta
*
1000000.0
/
N
)
assert
counter
==
0
,
counter
start
=
time
()
sleep
(
0
)
delta
=
time
()
-
start
assert
counter
==
N
,
(
counter
,
N
)
print
'switching: %d microseconds'
%
(
delta
*
1000000.0
/
N
)
elif
sys
.
argv
[
1
]
==
'eventletproc'
:
test
(
spawn
,
sleep
)
elif
sys
.
argv
[
1
]
==
'eventlet1'
:
from
eventlet.proc
import
spawn_greenlet
as
spawn
from
eventlet.api
import
sleep
,
use_hub
if
sys
.
argv
[
2
:]:
use_hub
(
sys
.
argv
[
2
])
start
=
time
()
for
_
in
xrange
(
N
):
spawn
(
incr
,
**
kwargs
)
delta
=
time
()
-
start
print
'spawning: %d microseconds'
%
(
delta
*
1000000.0
/
N
)
assert
counter
==
0
,
counter
start
=
time
()
sleep
(
0
)
delta
=
time
()
-
start
assert
counter
==
N
,
(
counter
,
N
)
print
'switching: %d microseconds'
%
(
delta
*
1000000.0
/
N
)
test
(
spawn
,
sleep
,
sleep
)
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