On Thu, Feb 20, 2020 at 12:22:53PM -0500, Greg Reagle wrote:
> Hello. I am amazed at how fast Lua is to start up and shut down. Is my 
> benchmark defective in any way? Lua seems to start up and exit faster than 
> bash, python, rc, and ksh. Dash and mksh are faster. These interpreters are 
> all packages from Debian Stable 10 "Buster".
>
> /usr/bin/time sh -c 'for i in $(seq 1 200); do dash -c "echo \"hello\""; 
> done' > /dev/null
> 0.12user 0.04system 0:00.17elapsed 97%CPU (0avgtext+0avgdata 1728maxresident)k
> 0inputs+0outputs (0major+16728minor)pagefaults 0swaps
>
> /usr/bin/time sh -c 'for i in $(seq 1 200); do mksh -c "echo \"hello\""; 
> done' >
> /dev/null
> 0.16user 0.05system 0:00.23elapsed 96%CPU (0avgtext+0avgdata 1904maxresident)k
> 0inputs+0outputs (0major+18472minor)pagefaults 0swaps
>
> /usr/bin/time sh -c 'for i in $(seq 1 200); do lua -e "print \"hello\""; 
> done' >
> /dev/null
> 0.22user 0.07system 0:00.31elapsed 97%CPU (0avgtext+0avgdata 2496maxresident)k
> 0inputs+0outputs (0major+25334minor)pagefaults 0swaps
>
> /usr/bin/time sh -c 'for i in $(seq 1 200); do bash -c "echo \"hello\""; 
> done' > /dev/null
> 0.26user 0.09system 0:00.36elapsed 96%CPU (0avgtext+0avgdata 3240maxresident)k
> 0inputs+0outputs (0major+30253minor)pagefaults 0swaps
>
> /usr/bin/time sh -c 'for i in $(seq 1 200); do ksh -c "echo \"hello\""; done' 
> > /dev/null
> 0.28user 0.14system 0:00.44elapsed 95%CPU (0avgtext+0avgdata 3888maxresident)k
> 0inputs+0outputs (0major+37146minor)pagefaults 0swaps
>
> /usr/bin/time sh -c 'for i in $(seq 1 200); do /usr/lib/plan9/bin/rc -c "echo 
> \"hello\""; done' > /dev/null
> 0.43user 0.14system 0:00.60elapsed 96%CPU (0avgtext+0avgdata 2008maxresident)k
> 0inputs+0outputs (0major+43700minor)pagefaults 0swaps
>
> /usr/bin/time sh -c 'for i in $(seq 1 200); do python -c "print \"hello\""; 
> done' > /dev/null
> 2.32user 0.88system 0:03.32elapsed 96%CPU (0avgtext+0avgdata 7220maxresident)k
> 0inputs+0outputs (0major+174760minor)pagefaults 0swaps
>

Why would it be "defective" other than sh or I/O adding time noise? lua is a
very simple language with a light reference interpreter. You should consider
tcl (through jimsh) too, I find this language way more elegant than these.

hadrien@gentoo-zen2700x> time sh -c 'for i in $(seq 1 200); do busybox ash -c 
"echo \"hello\""; done' > /dev/null
0.05s
hadrien@gentoo-zen2700x> time sh -c 'for i in $(seq 1 200); do bash -c "echo 
\"hello\""; done' > /dev/null
0.13s
hadrien@gentoo-zen2700x> time sh -c 'for i in $(seq 1 200); do python2 -c 
"print \"hello\""; done' > /dev/null
1.55s
hadrien@gentoo-zen2700x> time sh -c 'for i in $(seq 1 200); do python3 -c 
"print(\"hello\")"; done' > /dev/null
2.72s
hadrien@gentoo-zen2700x> time sh -c 'for i in $(seq 1 200); do perl -e "print 
\"hello\n\""; done' > /dev/null
0.17s
hadrien@gentoo-zen2700x> printf '%s\n' '#!/usr/bin/tclsh' 'puts hello' 
>hello.tcl
hadrien@gentoo-zen2700x> time sh -c 'for i in $(seq 1 200); do ./hello.tcl; 
done' > /dev/null
0.39s
hadrien@gentoo-zen2700x> time sh -c 'for i in $(seq 1 200); do jimsh -e "puts 
hello"; done' > /dev/null
0.18s
hadrien@gentoo-zen2700x> time sh -c 'for i in $(seq 1 200); do lua -e "print 
\"hello\""; done' > /dev/null
0.11s

What it shows is that python is slower than a dead rat and the reference tcl
could be better. Apart from that, they're all quite fast.
A much more accurate mesure of disgust is the number of syscall made for such a
simple task:

hadrien@gentoo-zen2700x> strace -fc busybox ash -c 'echo hello' 2>&1 >/dev/null 
| tail -n1 | awk '{print $3}'
26
hadrien@gentoo-zen2700x> strace -fc bash -c 'echo hello' 2>&1 >/dev/null | tail 
-n1 | awk '{print $3}'
132
hadrien@gentoo-zen2700x> strace -fc python2 -c 'print "hello"' 2>&1 >/dev/null 
| tail -n1 | awk '{print $3}'
683
hadrien@gentoo-zen2700x> strace -fc python3 -c 'print("hello")' 2>&1 >/dev/null 
| tail -n1 | awk '{print $3}'
517
hadrien@gentoo-zen2700x> strace -fc perl -e 'print("hello\n");' 2>&1 >/dev/null 
| tail -n1 | awk '{print $3}'
173
hadrien@gentoo-zen2700x> strace -fc ./hello.tcl 2>&1 >/dev/null | tail -n1 | 
awk '{print $3}'
190
hadrien@gentoo-zen2700x> strace -fc jimsh -e 'puts hello' 2>&1 >/dev/null | 
tail -n1 | awk '{print $3}'
78
hadrien@gentoo-zen2700x> strace -fc lua -e 'print "hello"' 2>&1 >/dev/null | 
tail -n1 | awk '{print $3}'
90

Speaks for itself.

Reply via email to