File: hub_timers.py

package info (click to toggle)
python-eventlet 0.40.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,200 kB
  • sloc: python: 25,101; sh: 78; makefile: 31
file content (36 lines) | stat: -rw-r--r-- 673 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'''Benchmark timer adds & expires on hubs.hub.BaseHub
'''
import contextlib
import random

import benchmarks
from eventlet.hubs import timer, get_hub


l = []
hub = get_hub()


def work(n):
    l.append(n)


@contextlib.contextmanager
def setup(iters):
    l[:] = []
    timeouts = [random.uniform(0, 10) for x in range(iters)]
    yield timeouts


@benchmarks.configure(manager=setup, scale_factor=3)
def benchmark_hub_timers(timeouts):
    scheduled = []

    for timeout in timeouts:
        t = timer.Timer(timeout, work, timeout)
        t.schedule()
        scheduled.append(t)

    hub.prepare_timers()
    hub.fire_timers(hub.clock() + 11)
    hub.prepare_timers()