Stephane Chazelas <stephane.chaze...@gmail.com> wrote: > 2017-05-16 17:29:13 +0100, Stephane Chazelas:
... > szsh a 0.763 > szsh b 0.622 > ksh93 a 0.667 > ksh93 b 0.464 > yash a 0.738 > yash b 0.429 > > In mksh, printf is not built-in which doesn't help. In all but > ksh93, that still does 5 forks because of the $(set +o). > > dash is the only one that manages to be quicker (not if I use > mawk instead of gawk though). dash is the one of the slowest shells. It appears to be fast because it does not support multi-byte characters, which disqualifies it for use in a normal UNIX environment. I made benchmarks with various shells and I know that in the Bourne Shell, 30% of the total CPU time is spent in the multibyte -> wide -> multibyte conversions that are needed to support stateful encodings. As a result, it is expected to see dash slower than bash in case it was enhanced to support multi byte chars. Here are my results: dash a 0,833 dash b 0,684 bash a 1,839 bash b 1,136 bosh a 1,441 bosh b 0,852 mksh a 3,601 mksh b 1,034 szsh a 1,791 szsh b 1,533 ksh a 2,970 ksh b 0,935 ksh93 a 1,303 ksh93 b 1,176 yash a 1,809 yash b 0,892 dash a 2,384 dash b 0,035 bash a 13,491 bash b 0,099 bosh a 4,400 bosh b 0,049 mksh a 20,927 mksh b 0,040 szsh a 4,771 szsh b 0,047 ksh a 13,634 ksh b 0,061 ksh93 a 1,318 ./b: line 2: 21650: Terminated ksh93 b 26,434 yash a 7,036 yash b 0,068 ksh88 is ksh... For some reason, the awk based example does not terminate with ksh93 in your second example. I had to kill it. As you see, if you only look at multi-byte enabled shells, the recent POSIX compliant Bourne Shell (bosh) and ksh93 are the fastest. Both ksh93 and bosh avoid forks and try to use vfork instead of fork whenever possible. Note that on a platform with a real vfork implementation (Solaris), vfork is aprox. 3x faster than fork even though fork on Solaris is a copy on write fork already. Linux does not implement a real vfork, as it just gives you the disadvantages of vfork and the shared data, while on Solaris, the vfork child borrows the address space description from the parent. Jörg -- EMail:jo...@schily.net (home) Jörg Schilling D-13353 Berlin joerg.schill...@fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/ URL: http://cdrecord.org/private/ http://sf.net/projects/schilytools/files/'