Compare
ela beside Bash, Python and Ruby.
The same things done in each language, where ela's ideas come from, and how fast ela runs beside Bash and Python. Each ela cell links its page in the manual.
The language
| Bash | Python | Ruby | ela | |
|---|---|---|---|---|
| Running a program | a line: git status | subprocess.run(["git", "status"]) | backticks, or system("git status") | a line: git status (Commands) |
| Values | text only, with arrays added on | str, int, list, dict and classes | everything an object | text, numbers, booleans, lists, maps, structs, enums and null; no classes |
| Reading a variable | $x, split into words and globbed unless quoted | x | x | $x, never split or globbed; an unset one is an error (Variables) |
| A failed command | ignored unless set -e, which has holes | an exception when asked: check=True | ignored unless checked | stops the script with where and why; err = try cmd gives null or an Error with the exit code and stderr (Error handling) |
| Adding context to an error | by hand: echo "loading the site: $msg" >&2; exit 1 | raise SiteError("loading the site") from e, shown as two tracebacks | raise SiteError, "loading the site" in a rescue, which sets cause | fail "loading the site", $err, which prints as one line, loading the site: reading config.toml: not found, and error.is($err, Error.NOT_FOUND) searches the chain (Errors as values) |
| Mistakes found before running | none: a syntax error stops the script when its line is reached | syntax, for the whole file | syntax, for the whole file | block grammar, dropped results and an assignment to env, args or Type, before line 1; --lint finds more |
| Blocks | if … fi, for … done | indentation | end | end, or end if, end for: a named end must match its block (Statements and blocks) |
| Choosing a value | case … esac, setting the variable in every branch | a dict: {"dir": "folder"}.get(kind, "file") | case … when gives a value | label = switch $kind, a value from each case; for two, if $n == 1; "file" else "files" (Values from switch and if) |
| A list from a loop | a loop that appends with +=: (( n % 2 == 0 )) && sq+=($((n * n))) | a comprehension: [n * n for n in nums if n % 2 == 0] | nums.select(&:even?).map { |n| n * n } | the loop, on one line: sq = for n in $nums when $n % 2 == 0; $n * $n (Lists from for) |
| Joining text | "$a$b" | +, f-strings | +, "#{a}" | interpolation, "${a}${b}"; + is arithmetic, and on text an error (Strings) |
| Scoped settings | a subshell, local | with | blocks: Dir.chdir(dir) { … } | with dir "build", env.X = "1", put back however the block is left |
| Cleanup | trap … EXIT | try … finally | ensure | defer |
| Background work | & and wait; a job can outlive the script | subprocess.Popen, threads, asyncio | spawn and Process.wait, threads | run and wait; a proc or a with block waits for the jobs it started (Process control) |
| Asking the user | read -p "Name? " name; select for a numbered menu | input("Name? "); a menu by hand | print "Name? ", then gets.chomp; a menu by hand | ask.yes("Delete 3 files?"), ask.choose("Deploy to?", $targets), read from the terminal even when stdin is a pipe (Asking the user) |
| A glob with no match | passed on as the pattern's text, unless shopt -s failglob | the glob module gives an empty list | Dir.glob gives an empty list | an error, as in zsh and fish (Strict rules) |
| Errors | terse | tracebacks | tracebacks | messages that say what to write instead, and --explain for each (Error messages) |
| Built-in data | none | a large standard library | a large standard library | JSON, TOML, YAML, CSV, tables, the keyring, hashes and files, built in |
| JSON to a table | jq -r '.data.orders[] | [.id, .customer.city] | @tsv', then a while read loop over the lines; a missing key an empty field | pandas: pd.json_normalize(json.loads(body)["data"]["orders"]), a nested key a column such as customer.city; a missing one NaN | JSON.parse(body).dig("data", "orders"), then map each order to an array by hand | t = json.table($body, at = "data.orders"); a nested value a column by its path, columns = {"city": "customer.city"}, and a row without it an error naming the row (Tables from JSON) |
| Style | anything | PEP 8, by convention | by convention | one layout from --fmt; --lint warns of a name off the naming style |
Where the ideas come from
| In ela | From |
|---|---|
A command is a line; pipes; $( ) captures output | Bash |
Lists, maps and the other types of value; with for a change the block puts back | Python |
Blocks closed by end, which may name its block: end if | Ruby and Lua; the named end from Ada |
defer, procs, and ..$xs to spread a list into a call | Go and Odin |
Errors as values, each wrapping its cause with what was being done: fail "loading the site", $err | Go |
| Errors that say what to write instead | Rust and Elm |
| A glob that matches nothing is an error | zsh and fish |
Speed
ela gains most where Bash starts a program for a small job. Reading the modes of 1,000 files takes Bash 2.7 s, because it starts stat for each one; ela takes 4.7 ms, because it reads them itself, and Python 20 ms. ela also starts faster than Bash, and ten times faster than Python. JSON goes into a table without a tree in between: json.table makes a table of five columns from 200,000 orders, 45 MB of JSON, in 0.17 s and 61 MB of memory at the peak, 45 MB of it the text itself. The same table through json.decode, tree.pick and table.of takes 0.68 s and 675 MB. Both were measured on the same machine and build. It trails in two places. Python runs a tight loop over numbers about 3.5 times faster than ela, which is why the translation check below is two and a half times faster in its original Python. And a loop in ela over work the original handed to a C program runs slower: a walk over text one character at a time, which Bash gave to a single awk, takes eight times as long in ela. Faster loops are next in ela's plans.
The house's scripts, moved to ela
The scripts that build and check this project's repositories, each beside its port to ela, on the same input: the median wall time of seven runs. The ports ran on ela's build at commit 124b88d.
| The job | Original | Original ms | ela ms |
|---|---|---|---|
| Check a library's cheat sheet against its API index | sh | 304 | 123 |
| Check a website's images and videos | Bash | 490 | 18 |
| Check a program's source strings against its translation catalogues | Python | 169 | 430 |
Write an API index of a library's packages, from odin doc | sh | 717 | 739 |
| Find the calls in a program's Odin source that open a path to classify it, a character at a time | Bash | 132 | 1,067 |
Three small measurements
Each is the median of five runs, timed by bench.ela below, on one machine, an Intel Core i7-13700K, under nice beside other work, with Bash 5.2, Python 3.15 and ela built for release from commit 124b88d. A cell is the middle of three such runs. The figures compare the three on that machine; a start-up of a few milliseconds moves by a few tenths between runs.
| The job | Bash ms | Python ms | ela ms |
|---|---|---|---|
Start-up: bash -c '', python3 -c '', ela -c '' | 2.6 | 16.2 | 1.6 |
1,000 file modes: modes.sh, modes.py, modes.ela | 2,728 | 19.8 | 4.7 |
1,000,000 additions: sum.sh, sum.py, sum.ela | 1,387 | 62.9 | 216 |
for i in {1..1000}; do m=$(stat -c %a f)doneimport os for i in range(1000): m = os.stat("f").st_mode & 0o7777for i in range(1000) m = file.mode("f")end forn=0for ((i = 0; i < 1000000; i++)); do ((n += i))doneecho $nn = 0for i in range(1000000): n += iprint(n)n = 0for i in range(1000000) n = $n + $iend forecho $n# Each case's commands, run turn about five times; the median wall time of each, in ms.# Run it beside the six scripts and an empty file f: ELA=$(command -v ela) ela bench.elaELA :: $env.ELACASES :: [ ["start-up", ["bash", "-c", ""], ["python3", "-c", ""], [$ELA, "-c", ""]], ["1,000 file modes", ["bash", "modes.sh"], ["python3", "modes.py"], [$ELA, "modes.ela"]], ["1,000,000 additions", ["bash", "sum.sh"], ["python3", "sum.py"], [$ELA, "sum.ela"]],] proc timed(cmd: list) -> number t = time.now() $cmd > /dev/null return time.since($t) * 1000end proc proc median(xs: list) -> number s = list.sort($xs) return int($s[len($s) // 2] * 10) / 10end proc for c in $CASES b = [] p = [] e = [] for round in range(5) b = list.append($b, timed($c[1])) p = list.append($p, timed($c[2])) e = list.append($e, timed($c[3])) end for mb = median($b) mp = median($p) me = median($e) echo "$c[0]: bash $mb ms, python $mp ms, ela $me ms"end for