Last active
January 9, 2017 07:08
-
-
Save mafredri/2132136366854323f0b5aa6d41c7ab2f to your computer and use it in GitHub Desktop.
Benchmark opening new zpty instances vs keeping a long running one (zsh-async) for executing asynchronous tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Start async job (async_job): | |
1: 0.00011992 | |
2: 0.00011015 | |
3: 0.00010586 | |
4: 0.00010514 | |
5: 0.00022697 | |
6: 0.00013900 | |
7: 0.00010586 | |
8: 0.00010395 | |
9: 0.00011015 | |
10: 0.00012779 | |
11: 0.00025320 | |
12: 0.00010586 | |
13: 0.00010514 | |
14: 0.00017095 | |
15: 0.00011301 | |
16: 0.00007391 | |
17: 0.00010395 | |
18: 0.00011301 | |
19: 0.00007701 | |
20: 0.00010419 | |
21: 0.00012589 | |
22: 0.00011301 | |
23: 0.00010800 | |
24: 0.00030208 | |
25: 0.00021291 | |
26: 0.00067711 | |
27: 0.00044680 | |
28: 0.00010204 | |
29: 0.00204992 | |
30: 0.00011110 | |
31: 0.00139713 | |
32: 0.00011921 | |
33: 0.00012207 | |
34: 0.00019407 | |
35: 0.00015116 | |
36: 0.00011802 | |
37: 0.00012589 | |
38: 0.00028801 | |
39: 0.00036597 | |
40: 0.00012112 | |
41: 0.00012088 | |
42: 0.00007606 | |
43: 0.00013494 | |
44: 0.00052691 | |
45: 0.00402522 | |
46: 0.00013113 | |
47: 0.00062108 | |
48: 0.00053501 | |
49: 0.00569916 | |
50: 0.00015306 | |
51: 0.00011587 | |
52: 0.00063205 | |
53: 0.00011897 | |
54: 0.00011301 | |
55: 0.00069380 | |
56: 0.00011992 | |
57: 0.00082994 | |
58: 0.00011492 | |
59: 0.00011420 | |
60: 0.00020599 | |
61: 0.00011802 | |
62: 0.00011206 | |
63: 0.00011086 | |
64: 0.00516987 | |
65: 0.00037599 | |
66: 0.00057292 | |
67: 0.00010800 | |
68: 0.00012112 | |
69: 0.00011587 | |
70: 0.00015092 | |
71: 0.00016308 | |
72: 0.00103092 | |
73: 0.00055313 | |
74: 0.00021219 | |
75: 0.00074387 | |
76: 0.00029206 | |
77: 0.00013494 | |
78: 0.00013900 | |
79: 0.00027513 | |
80: 0.00013995 | |
81: 0.00012898 | |
82: 0.00017405 | |
83: 0.00014782 | |
84: 0.00011516 | |
85: 0.00058794 | |
86: 0.00052714 | |
87: 0.01539993 | |
88: 0.00013995 | |
89: 0.00010800 | |
90: 0.00012207 | |
91: 0.00017524 | |
92: 0.00010586 | |
93: 0.00011802 | |
94: 0.00011992 | |
95: 0.00012398 | |
96: 0.00011110 | |
97: 0.00011992 | |
98: 0.00012398 | |
99: 0.00012493 | |
100: 0.00039101 | |
Start a new new zpty instance (zpty [name] [cmd]): | |
1: 0.10629606 | |
2: 0.00747418 | |
3: 0.00503302 | |
4: 0.00421691 | |
5: 0.00529718 | |
6: 0.00768995 | |
7: 0.00402498 | |
8: 0.01689005 | |
9: 0.03123999 | |
10: 0.02620292 | |
11: 0.00464106 | |
12: 0.00983191 | |
13: 0.00790000 | |
14: 0.01226807 | |
15: 0.00578904 | |
16: 0.01287699 | |
17: 0.01755691 | |
18: 0.00741816 | |
19: 0.00440884 | |
20: 0.00704098 | |
21: 0.00471997 | |
22: 0.00458884 | |
23: 0.00816512 | |
24: 0.00919509 | |
25: 0.00691605 | |
26: 0.00646615 | |
27: 0.00671005 | |
28: 0.00595784 | |
29: 0.00413108 | |
30: 0.00610518 | |
31: 0.00441480 | |
32: 0.01003003 | |
33: 0.00547695 | |
34: 0.00462103 | |
35: 0.00391603 | |
36: 0.00483608 | |
37: 0.00748801 | |
38: 0.00438690 | |
39: 0.00626397 | |
40: 0.00413489 | |
41: 0.00455499 | |
42: 0.00863695 | |
43: 0.01012516 | |
44: 0.01047206 | |
45: 0.01412702 | |
46: 0.01219606 | |
47: 0.00425291 | |
48: 0.00784206 | |
49: 0.00507498 | |
50: 0.00349689 | |
51: 0.00353885 | |
52: 0.01486802 | |
53: 0.00418711 | |
54: 0.00674796 | |
55: 0.00422812 | |
56: 0.00342393 | |
57: 0.01739097 | |
58: 0.00407696 | |
59: 0.02471113 | |
60: 0.00368285 | |
61: 0.00658989 | |
62: 0.00815701 | |
63: 0.00568414 | |
64: 0.01950502 | |
65: 0.00754786 | |
66: 0.02570510 | |
67: 0.01920891 | |
68: 0.00612020 | |
69: 0.00598097 | |
70: 0.01401091 | |
71: 0.01317191 | |
72: 0.02514696 | |
73: 0.00415421 | |
74: 0.00795293 | |
75: 0.00428200 | |
76: 0.00996590 | |
77: 0.01114607 | |
78: 0.00607800 | |
79: 0.01548910 | |
80: 0.00967598 | |
81: 0.00422120 | |
82: 0.00505090 | |
83: 0.00601292 | |
84: 0.00506306 | |
85: 0.00886297 | |
86: 0.00738907 | |
87: 0.00542116 | |
88: 0.00583386 | |
89: 0.00608206 | |
90: 0.00439596 | |
91: 0.00546885 | |
92: 0.00471997 | |
93: 0.00410795 | |
94: 0.02467012 | |
95: 0.00435495 | |
96: 0.00285101 | |
97: 0.00867701 | |
98: 0.00430083 | |
99: 0.01618814 | |
100: 0.01155686 | |
Start a new new buffered zpty instance (zpty -b [name] [cmd]): | |
1: 0.00286913 | |
2: 0.00600505 | |
3: 0.00419998 | |
4: 0.00362182 | |
5: 0.00882602 | |
6: 0.00745988 | |
7: 0.00625992 | |
8: 0.00242305 | |
9: 0.00479794 | |
10: 0.00539899 | |
11: 0.00788593 | |
12: 0.00690198 | |
13: 0.00278115 | |
14: 0.00248790 | |
15: 0.00578904 | |
16: 0.00886607 | |
17: 0.00605917 | |
18: 0.00497389 | |
19: 0.00333619 | |
20: 0.00235510 | |
21: 0.00412416 | |
22: 0.00793004 | |
23: 0.00672507 | |
24: 0.00429606 | |
25: 0.00438404 | |
26: 0.00514197 | |
27: 0.00270200 | |
28: 0.00892615 | |
29: 0.00380087 | |
30: 0.00383520 | |
31: 0.00274420 | |
32: 0.00416398 | |
33: 0.00258207 | |
34: 0.00962591 | |
35: 0.00491714 | |
36: 0.00361204 | |
37: 0.00411797 | |
38: 0.00237918 | |
39: 0.00352001 | |
40: 0.00250196 | |
41: 0.00392509 | |
42: 0.00625801 | |
43: 0.00526190 | |
44: 0.00353098 | |
45: 0.00257492 | |
46: 0.00246501 | |
47: 0.00385594 | |
48: 0.00418592 | |
49: 0.00718617 | |
50: 0.00519514 | |
51: 0.00354099 | |
52: 0.00391006 | |
53: 0.00234604 | |
54: 0.00427699 | |
55: 0.00428796 | |
56: 0.00570488 | |
57: 0.00420403 | |
58: 0.00372195 | |
59: 0.00296307 | |
60: 0.00336504 | |
61: 0.00242996 | |
62: 0.00647783 | |
63: 0.00644302 | |
64: 0.00414920 | |
65: 0.00340891 | |
66: 0.00272202 | |
67: 0.00317907 | |
68: 0.00258803 | |
69: 0.00189495 | |
70: 0.00255203 | |
71: 0.00725508 | |
72: 0.00534201 | |
73: 0.00323606 | |
74: 0.00387001 | |
75: 0.00243402 | |
76: 0.00381517 | |
77: 0.00226593 | |
78: 0.00592899 | |
79: 0.00616407 | |
80: 0.00460601 | |
81: 0.00364304 | |
82: 0.00264478 | |
83: 0.00250101 | |
84: 0.00242996 | |
85: 0.00260687 | |
86: 0.00514603 | |
87: 0.00788879 | |
88: 0.00370097 | |
89: 0.00385118 | |
90: 0.00245595 | |
91: 0.00328898 | |
92: 0.00226188 | |
93: 0.00226903 | |
94: 0.00443721 | |
95: 0.00662899 | |
96: 0.00389481 | |
97: 0.00331998 | |
98: 0.00317192 | |
99: 0.00177884 | |
100: 0.00373602 | |
Benchmark: Write command to zpty (zpty -w): | |
1: 0.00007200 | |
2: 0.00007796 | |
3: 0.00041294 | |
4: 0.00041389 | |
5: 0.00012708 | |
6: 0.00028396 | |
7: 0.00007200 | |
8: 0.00009179 | |
9: 0.00009799 | |
10: 0.00005507 | |
11: 0.00005698 | |
12: 0.00006604 | |
13: 0.00037098 | |
14: 0.00034213 | |
15: 0.00012803 | |
16: 0.00018382 | |
17: 0.00008798 | |
18: 0.00012994 | |
19: 0.00009704 | |
20: 0.00013804 | |
21: 0.00009489 | |
22: 0.00011301 | |
23: 0.00008082 | |
24: 0.00007510 | |
25: 0.00010014 | |
26: 0.00009704 | |
27: 0.00010014 | |
28: 0.00008011 | |
29: 0.00023913 | |
30: 0.00008106 | |
31: 0.00019288 | |
32: 0.00016189 | |
33: 0.00008416 | |
34: 0.00011396 | |
35: 0.00007200 | |
36: 0.00007319 | |
37: 0.00005698 | |
38: 0.00005698 | |
39: 0.00006795 | |
40: 0.00010300 | |
41: 0.00034118 | |
42: 0.00036502 | |
43: 0.00009799 | |
44: 0.00030398 | |
45: 0.00009489 | |
46: 0.00010991 | |
47: 0.00009179 | |
48: 0.00013590 | |
49: 0.00008297 | |
50: 0.00019288 | |
51: 0.00008607 | |
52: 0.00012994 | |
53: 0.00018406 | |
54: 0.00013685 | |
55: 0.00019217 | |
56: 0.00011396 | |
57: 0.00005817 | |
58: 0.00012302 | |
59: 0.00012708 | |
60: 0.00010085 | |
61: 0.00007415 | |
62: 0.00006986 | |
63: 0.00009012 | |
64: 0.00005388 | |
65: 0.00005889 | |
66: 0.00006413 | |
67: 0.00005698 | |
68: 0.00005293 | |
69: 0.00005913 | |
70: 0.00037479 | |
71: 0.00023985 | |
72: 0.00009489 | |
73: 0.00015187 | |
74: 0.00020289 | |
75: 0.00008011 | |
76: 0.00007200 | |
77: 0.00005293 | |
78: 0.00005507 | |
79: 0.00005579 | |
80: 0.00011802 | |
81: 0.00018191 | |
82: 0.00019193 | |
83: 0.00011206 | |
84: 0.00010705 | |
85: 0.00008488 | |
86: 0.00007200 | |
87: 0.00005817 | |
88: 0.00005198 | |
89: 0.00005198 | |
90: 0.00011015 | |
91: 0.00016904 | |
92: 0.00136900 | |
93: 0.00007200 | |
94: 0.00008917 | |
95: 0.00164294 | |
96: 0.00006700 | |
97: 0.00048399 | |
98: 0.00053811 | |
99: 0.00007606 | |
100: 0.00048709 | |
Benchmark: Launch regular child proc (cmd &): | |
1: 0.00889206 | |
2: 0.00211501 | |
3: 0.00090313 | |
4: 0.00087500 | |
5: 0.00058913 | |
6: 0.00086999 | |
7: 0.00069499 | |
8: 0.00086498 | |
9: 0.00257611 | |
10: 0.00064802 | |
11: 0.00063801 | |
12: 0.00063610 | |
13: 0.00089383 | |
14: 0.00065613 | |
15: 0.00058699 | |
16: 0.00073600 | |
17: 0.00210595 | |
18: 0.00062013 | |
19: 0.00068998 | |
20: 0.00069404 | |
21: 0.00081205 | |
22: 0.00062108 | |
23: 0.00060391 | |
24: 0.00064492 | |
25: 0.00077510 | |
26: 0.00142384 | |
27: 0.00061703 | |
28: 0.00070000 | |
29: 0.00141788 | |
30: 0.00239897 | |
31: 0.00064921 | |
32: 0.00064492 | |
33: 0.00331903 | |
34: 0.00061393 | |
35: 0.00070715 | |
36: 0.00078106 | |
37: 0.00058913 | |
38: 0.00068903 | |
39: 0.00083017 | |
40: 0.00081396 | |
41: 0.00302291 | |
42: 0.00150013 | |
43: 0.00070691 | |
44: 0.00064802 | |
45: 0.00237012 | |
46: 0.00065303 | |
47: 0.00095201 | |
48: 0.00353289 | |
49: 0.00061703 | |
50: 0.00069094 | |
51: 0.00060916 | |
52: 0.00078011 | |
53: 0.00076818 | |
54: 0.00091600 | |
55: 0.00066900 | |
56: 0.00221491 | |
57: 0.00214195 | |
58: 0.00065589 | |
59: 0.00066614 | |
60: 0.00114393 | |
61: 0.00083184 | |
62: 0.00220704 | |
63: 0.00329614 | |
64: 0.00059605 | |
65: 0.00067616 | |
66: 0.00218987 | |
67: 0.00203395 | |
68: 0.00070810 | |
69: 0.00073099 | |
70: 0.00622892 | |
71: 0.00382781 | |
72: 0.00086904 | |
73: 0.00065517 | |
74: 0.00059414 | |
75: 0.00084710 | |
76: 0.00154805 | |
77: 0.00062895 | |
78: 0.00083995 | |
79: 0.00060487 | |
80: 0.00062919 | |
81: 0.00257897 | |
82: 0.00054789 | |
83: 0.00065589 | |
84: 0.00065184 | |
85: 0.00089312 | |
86: 0.00280595 | |
87: 0.00062799 | |
88: 0.00064206 | |
89: 0.00083709 | |
90: 0.00131297 | |
91: 0.00065494 | |
92: 0.00065899 | |
93: 0.00155687 | |
94: 0.00062180 | |
95: 0.00071907 | |
96: 0.00246000 | |
97: 0.00060320 | |
98: 0.00066400 | |
99: 0.00192881 | |
100: 0.00233102 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh -i | |
emulate -L zsh | |
unsetopt monitor | |
source async.zsh | |
async_init | |
async_runner() { | |
emulate -L zsh | |
[[ $1 = read ]] && read -r async_cmd | |
integer notify_parent parent_pid | |
# Process option parameters passed to worker | |
while getopts "np:u" opt; do | |
case $opt in | |
n) notify_parent=1;; | |
p) parent_pid=$OPTARG;; | |
esac | |
done | |
local stdout stderr ret | |
float -F duration=$EPOCHREALTIME | |
{ | |
stdout=$(eval "$async_cmd") | |
ret=$? | |
duration=$(( EPOCHREALTIME - duration )) # Calculate duration. | |
# (( notify_parent )) && kill -ALRM $parent_pid | |
print -r -n - $ret $duration ${(q)stdout} | |
} 2> >(stderr=$(cat); print -r -n - " "${(q)stderr}) | |
# while :; do sleep 3600; done | |
} | |
async_fn() { | |
print $'hello \n world' | |
} | |
local async_cmd=(async_fn) | |
float -F start stop | |
print "Start async job (async_job):" | |
for i in {1..100}; do | |
async_start_worker test | |
start=$EPOCHREALTIME | |
async_job test async_fn | |
stop=$(( EPOCHREALTIME - start )) | |
printf "%4d: %.8f\n" $i $stop | |
async_stop_worker test | |
done | |
print "Start a new new zpty instance (zpty [name] [cmd]):" | |
for i in {1..100}; do | |
start=$EPOCHREALTIME | |
zpty test async_runner -p $$ -n | |
stop=$(( EPOCHREALTIME - start )) | |
printf "%4d: %.8f\n" $i $stop | |
zpty -d test | |
done | |
print "Start a new new buffered zpty instance (zpty -b [name] [cmd]):" | |
for i in {1..100}; do | |
start=$EPOCHREALTIME | |
zpty -b test async_runner read -p $$ -n | |
stop=$(( EPOCHREALTIME - start )) | |
printf "%4d: %.8f\n" $i $stop | |
zpty -d test | |
done | |
print "Benchmark: Write command to zpty (zpty -w):" | |
for i in {1..100}; do | |
zpty test async_runner read -p $$ -n | |
start=$EPOCHREALTIME | |
zpty -w test async_fn | |
stop=$(( EPOCHREALTIME - start )) | |
printf "%4d: %.8f\n" $i $stop | |
zpty -d test | |
done | |
print "Benchmark: Launch regular child proc (cmd &):" | |
for i in {1..100}; do | |
start=$EPOCHREALTIME | |
async_runner >/dev/null & | |
stop=$(( EPOCHREALTIME - start )) | |
printf "%4d: %.8f\n" $i $stop | |
wait | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment