bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

JIT in bash


From: Peng Yu
Subject: JIT in bash
Date: Thu, 3 Jan 2019 10:02:21 -0600

The following test cases show that the variable length can
significantly affect the runtime in bash. But the variable length
doesn't seem to have a significant effect in some other interpreted
languages, such as python.

I can understand that variables length will slow down the runtime, as
bash is interpreted. But I didn't expect that it should slow down the
runtime so much. Does anybody happen to know the cause of the problem
on why bash is slowed down so much compared with python when the
variable length is increased?

One way that I think can mitigate (but not solve the original problem)
the problem is to use just-in-time (JIT) compilation.

Python has a JIT compiler pypy. However, I don't see that bash has a
JIT compiler. Is it because people think that bash is just a glue
language so that making it run faster is not important, therefore
there is no need to make a JIT compiler for bash?

Or it is because the current bash code started very early and has
certain limitation which makes it hard to create a new JIT compiler
based on it?

$ cat ./main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

TIMEFORMAT=%R
set -v
time for ((i=0;i<10000;++i)); do
    :
done > /dev/null

time for 
((iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii=0;iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii<10000;++iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii));
do
    :
done > /dev/null

time ./main.py 1000000
time ./main.py 10000000
time ./main_long.py 1000000
time ./main_long.py 10000000
$ cat main.py
#!/usr/bin/env python
# vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:

import sys
for i in xrange(int(sys.argv[1])):
    pass
$ ./main.sh
time for ((i=0;i<10000;++i)); do
    :
done > /dev/null
0.148

time for 
((iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii=0;iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii<10000;++iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii));
do
    :
done > /dev/null
0.321

time ./main.py 1000000
0.188
time ./main.py 10000000
0.822
time ./main_long.py 1000000
0.164
time ./main_long.py 10000000
0.945


-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]