-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch-perf.py
More file actions
executable file
·76 lines (59 loc) · 2.27 KB
/
launch-perf.py
File metadata and controls
executable file
·76 lines (59 loc) · 2.27 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python
__author__ = 'ed'
import os
import sys
from resource import getrusage as resource_usage, RUSAGE_SELF
from time import time as timestamp
from multiprocessing import Process, Queue, Pipe
def trueit_local():
return True
def trueit_queue(q):
q.put(True)
def trueit_pipe(conn):
conn.send(True)
conn.close()
if __name__ == '__main__':
reps = int(sys.argv[1])
if reps != 0:
for test in sys.argv[2:]:
start_time, start_resources = timestamp(), resource_usage(RUSAGE_SELF)
if test == '1':
print('os.system(\'true\') =')
for i in xrange(0, reps):
os.system('true')
elif test == '2':
print('python local call, \'True\' =')
for i in xrange(0, reps):
trueit_local()
elif test == '3':
print('os.system, python executable =')
for i in xrange(0, reps):
command = sys.argv[0] + " 0 2"
os.system(command)
elif test == '4':
q = Queue()
print('multiprocess, queue =')
for i in xrange(0, reps):
p = Process(target=trueit_queue, args=(q,))
p.start()
r = q.get()
p.join()
elif test == '5':
print('multiprocess, pipe =')
parent_conn, child_conn = Pipe()
for i in xrange(0, reps):
p = Process(target=trueit_pipe, args=(child_conn,))
p.start()
r = parent_conn.recv()
p.join()
elif test == '6':
print('os.system, python executable =')
for i in xrange(0, reps):
command = "/usr/bin/salt-call test.ping"
os.system(command)
end_resources, end_time = resource_usage(RUSAGE_SELF), timestamp()
results = {'real': end_time - start_time,
'sys': end_resources.ru_stime - start_resources.ru_stime,
'user': end_resources.ru_utime - start_resources.ru_utime}
print results
print '=', reps / results['real'], 'calls per second\n'