summaryrefslogtreecommitdiff
path: root/benchmarks/hub_timers.py
blob: f5a2b81f499e87a905b8d1fe1af9957d80be983d (plain)
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
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env python
from __future__ import print_function

# test timer adds & expires on hubs.hub.BaseHub

import sys
import eventlet
import random
import time

from eventlet.hubs import timer, get_hub
from eventlet.support import six


timer_count = 100000

if len(sys.argv) >= 2:
    timer_count = int(sys.argv[1])

l = []


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

timeouts = [random.uniform(0, 10) for x in six.moves.range(timer_count)]

hub = get_hub()

start = time.time()

scheduled = []

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

    scheduled.append(t)

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

end = time.time()

print("Duration: %f" % (end - start,))