6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

色々な言語でたらい回し関数の速度を比較してみた その2

Last updated at Posted at 2024-09-11

はじめに

「たらい回し関数」として知られる 竹内関数 を色々な言語で動かして、完了するまでの時間を測ってみました。色々な言語で計算速度を比較してみた の記事を読んだことがあり、似たようなことをやってみたいと思ってました。

これ の続きです。これまでは Raspberry Pi 5 上で動かしていたのですが、動かない・動かせない言語がかなりありました、

ゆるい感じで更新を続けていく予定です。

更新

過去の更新

動作環境

  • Beelink EQ12
    • CPU: Intel N100
    • Memory: 16 GB

そんな速くないです。

測定内容

Tarai(x, y, z) に、初期値を x = 15, y = 5 として計算を行い、その処理時間を \time で測定します。Go 言語で 5 ~ 6 秒かかる処理になります。

結果

グラフ

全体 (対数)

大きいグラフ

0 ~ 10 秒

2 ~ 6 秒

経過時間
言語 ビルド 時間
Ada gnat-14 make -o a.out tarai.adb 6.97
Ada gnat-14 make -O1 -o a.out tarai.adb 5.61
Ada gnat-14 make -O2 -o a.out tarai.adb 5.34
Ada gnat-14 make -O3 -o a.out tarai.adb 3.13
Algol a68g tarai.alg 471.05
Ante ante -b tarai.an 19.91
Ante ante -b -O1 tarai.an 16.26
Ante ante -b -O2 tarai.an 18.69
Ante ante -b -O3 tarai.an 18.70
Arkscript arkscript tarai.ark 703.28
Arkscript arkscript -c tarai.ark 695.89
Austral austral compile tarai.aum --entrypoint=Tarai:main --output=a.out 11.69
Ballerina bal build tarai.bal 11.78
C gcc-14 tarai.c -lm 6.03
C gcc-14 -Ofast tarai.c -lm 2.57
C clang-18 tarai.c -lm 5.78
C clang-18 -Ofast tarai.c -lm 4.27
Chez Scheme chez --script tarai.ss 7.10
Chicken csc tarai.scm 69.40
Chicken csc -O1 tarai.scm 69.28
Chicken csc -O2 tarai.scm 69.23
Chicken csc -O3 tarai.scm 64.40
Chicken csc -O4 tarai.scm 64.98
Clio node .clio/index.js 8.43
Clio bun .clio/index.js 14.63
Clojure lein uberjar 8.94
COBOL cobc -x -free -o ./a.out ./tarai.cbl 2212.79
COBOL cobc -x -free -O2 -o ./a.out ./tarai.cbl 2164.89
Common Lisp clisp -c tarai.lsp 105.04
Concurnas concc tarai.conc 20.87
C++ g++-14 tarai.cpp 6.74
C++ g++-14 -Ofast tarai.cp 2.56
C++ clang++-18 tarai.cpp 5.83
C++ clang++-18 -Ofast tarai.cpp 4.27
Crystal crystal run src/tarai.cr 7.27
Crystal crystal build src/tarai.cr 5.91
Crystal crystal build --release src/tarai.cr 4.27
Crystal crystal build -O1 src/tarai.cr 3.87
Crystal crystal build -O2 src/tarai.cr 3.81
Crystal crystal build -O3 src/tarai.cr 4.87
C# dotnet build 10.66
C# dotnet publish 3.13
Cyber cyber tarai.cy 29.97
D gdc-14 -o a.out tarai.d 6.58
D gdc-14 -Ofast -o a.out tarai.d 2.43
D ldc2 tarai.d 5.13
D ldc2 --O3 tarai.d 4.27
Dart dart run tarai.dart 7.88
Dart dart compile exe tarai.dart 5.23
Dart dart compile jit-snapshot tarai.dart 7.51
Dart dart compile js tarai.dart -o tarai.js 10.43
Dictu dictu tarai.du 107.42
Draco dotnet build 11.30
Draco dotnet publish 8.62
Elixir mix escript.build 10.83
Erlang rebar3 escriptize 7.97
Fantom fan tarai.fan 4.81
Flix flix run 50.25
Flix flix build-jar 20.91
Fortran gfortran -o a.out tarai.f90 7.09
Fortran gfortran -Ofast -o a.out tarai.f90 3.07
F# dotnet build 7.59
F# dotnet publish 5.59
Gambit gsc -exe tarai.scm 5.59
Gauche gosh tarai.scm 73.39
Gleam gleam build 10.70
Go go build 5.31
Gravity gravity tarai.gravity 145.05
Groovy groovy tarai.groovy 18.20
Groovy groovy --compile-static tarai.groovy 5.80
Groovy groovy --type-checked tarai.groovy 18.51
Groovy groovy --compile-static --type-checked tarai.groovy 5.83
Guile guile -s tarai.scm 5.83
Haskell cabal build 5.76
Haxe haxe --main Tarai --jvm Tarai.jar 4.66
Haxe haxe -D analyzer-optimize --main Tarai --jvm Tarai.jar 3.57
Hy hy -i < tarai.hy 129.47
Idris2 idris2 tarai.idr -o a.out 51.49
Inko inko build tarai.inko 24.87
Inko inko build --opt balanced tarai.inko 24.85
Inko inko build --opt aggressive tarai.inko 11.94
Io io ./tarai.io 3949.96
Java java Tarai.java 5.09
Java javac Tarai.java 4.65
Javascript node tarai.js 10.43
Javascript deno run tarai.js 11.49
Javascript bun run tarai.js 12.43
Julia julia tarai.jl 6.78
Julia julia -O1 tarai.jl 6.42
Julia julia -O2 tarai.jl 6.77
Julia julia -O3 tarai.jl 6.77
Koka koka -c -j4 -O3 -v0 -r -o a.out tarai.kk 7.82
Kotlin kotlinc Tarai.kt -include-runtime -d Tarai.jar 6.77
LEAN4 lake build 11.32
LiveScript lsc tarai.ls 10.92
Lobster lobster --pak tarai.lobster 112.05
Lua lua tarai.lua 72.51
Lua luajit tarai.lua 11.18
Mercury mmc -o a.out tarai.m 3.46
Mercury mmc -O6 -o a.out tarai.m 4.79
Mojo mojo build tarai.🔥 5.38
Nelua nelua tarai.nelua 4.42
Nelua nelua --release tarai.nelua 4.42
Nelua nelua --maximum-performance tarai.nelua 2.46
Nim nim c -d:release --opt:size --hints:off -o:a.out tarai.nim 5.38
Nim nim cpp -d:release --opt:size --hints:off -o:a.out tarai.nim 5.59
Nim nim c -d:release --opt:speed --hints:off -o:a.out tarai.nim 5.02
Nim nim cpp -d:release --opt:speed --hints:off -o:a.out tarai.nim 2.35
Nit nitc -o a.out tarai.nit 6.19
Nit nitc --release -o a.out tarai.nit 6.15
Nit nitc --no-check-all -o a.out 6.15
OCaml dune build 4.79
Odin odin build tarai.odin -file 6.27
Odin odin build tarai.odin -o:speed -file 3.98
Odin odin build tarai.odin -o:speed -no-bounds-check -file 5.37
Odin odin build tarai.odin -o:speed -thread-count:4 -file 3.98
Odin odin build tarai.odin -o:speed -no-bounds-check -thread-count:4 -file 5.37
Onyx onyx run tarai.onyx 6.92
Onyx onyx build tarai.onyx 6.86
Pascal fpc tarai.pas 8.26
Pascal fpc -O4 tarai.pas 5.90
Peregrine peregrine.elf compile tarai.pe -o a.out 7.00
Peregrine peregrine.elf compile tarai.pe -static -o a.out 7.00
Peregrine peregrine.elf compile tarai.pe -release -o a.out 3.98
Peregrine peregrine.elf compile tarai.pe -release -static -o a.out 3.98
Perl perl tarai.pl 601.45
Php php tarai.php 58.44
Pike pike tarai.pike 152.94
Pinecone pinecone tarai.pn 1867.72
Poly/ML polyc tarai.ml 6.68
Pony ponyc -b a.out 5.78
Python python3 tarai.py 131.03
R Rscript tarai.R 3365.85
Racket racket tarai.rkt 7.27
Racket raco exe tarai.rkt 6.58
Racket raco make tarai.rkt 6.73
Raku raku tarai.p6 518.38
Raku raku --optimize=1 tarai.p6 1374.61
Raku raku --optimize=2 tarai.p6 515.44
Raku raku --optimize=3 tarai.p6 513.60
Reason dune build 4.79
ReScript node src/tarai.res.mjs 9.13
ReScript deno run src/tarai.res.mjs 9.60
ReScript bun run src/tarai.res.mjs 13.08
Ring ring2exe tarai.ring -static 2037.11
Ruby ruby tarai.rb 81.58
Ruby ruby --yjit tarai.rb 15.12
Rune rune run tarai.rn 642.86
Rust cargo build --release 4.00
Scala scala ./src/main/scala/Tarai.scala 4.38
Scala sbt assembly 4.02
Seed7 s7c tarai.sd7 8.69
Seed7 s7c -O3 tarai.sd7 2.96
Seed7 s7c -O3 -oc3 tarai.sd7 3.38
Squirrel sq -c tarai.nut 198.88
SWI-Prolog swipl -O -g main -o a.out -c tarai.swi 240.84
Swift swift build 34.15
Swift swift build -c release 4.71
V v run tarai.v 7.47
V v -prod -cc gcc-14 -skip-unused -manualfree -prealloc -gc none -no-bounds-checking -o a.out tarai.v 2.57
V v -prod -cc clang-18 -skip-unused -manualfree -prealloc -gc none -no-bounds-checking -o a.out tarai.v 4.27
Vala valac -o a.out tarai.vala 6.79
Zig zig build-exe tarai.zig 5.96
Zig zig build-exe -OReleaseFast tarai.zig 3.82
Zig zig build-exe -OReleaseSafe tarai.zig 4.04
Zig zig build-exe -OReleaseSmall tarai.zig 5.38
バージョン
言語 バージョン
Ada GNAT 14.0.1 20240412 (experimental) [master r14-9935-g67e1433a94f]
Algol Algol 68 Genie 3.1.2
Ante ante 0.1.1
Arkscript 4.0.0-3c9e3ab5
Austral 0.2.0
Ballerina Ballerina 2201.10.0 (Swan Lake Update 10)
C gcc-14 (Homebrew GCC 14.2.0) 14.2.0
C Ubuntu clang version 18.1.3 (1ubuntu1)
Chez Scheme 10.0.0
Chicken Version 5.4.0 (rev 1a1d1495)
Clio 0.12.0
Clojure Leiningen 2.11.2 on Java 22.0.2 Java HotSpot(TM) 64-Bit Server VM
COBOL cobc (GnuCOBOL) 3.1.2.0
Common Lisp GNU CLISP 2.49.92 (2018-02-18) (built on a969dca806f5 [172.18.0.2])
Concurnas Concurnas version: 1.14.020
C++ g++-14 (Homebrew GCC 14.2.0) 14.2.0
C++ Ubuntu clang version 18.1.3 (1ubuntu1)
Crystal Crystal 1.13.2 [879ec1247] (2024-08-20)
C# 8.0.401
Cyber Cyber 0.3 build-0-13a7bef
D gdc-14 (Ubuntu 14-20240412-0ubuntu1) 14.0.1 20240412 (experimental) [master r14-9935-g67e1433a94f]
D LDC - the LLVM D compiler (1.39.0):
Dart Dart SDK version: 3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "linux_x64"
Dictu Dictu Version: 0.30.0
Draco 8.0.401
Elixir Elixir 1.17.2 (compiled with Erlang/OTP 27)
Erlang rebar 3.24.0 on Erlang/OTP 27 Erts 15.0.1
Fantom fan.version: 1.0.80
Flix The Flix Programming Language 0.50.0
Fortran GNU Fortran (Homebrew GCC 14.2.0) 14.2.0
F# 8.0.401
Gambit v4.9.5 20230726044844 x86_64-pc-linux-gnu
Gauche Gauche scheme shell, version 0.9.15 [utf-8,pthreads], x86_64-pc-linux-gnu
Gleam gleam 1.4.1
Go go version go1.23.0 linux/amd64
Gravity Gravity version 0.8.5 (Jul 22 2021)
Groovy Groovy Version: 4.0.22 JVM: 22.0.2 Vendor: Oracle Corporation OS: Linux
Guile guile (GNU Guile) 3.0.10
Haskell The Glorious Glasgow Haskell Compilation System, version 9.4.8
Haxe 4.3.6
Hy hy 0.29.0
Idris2 Idris 2, version 0.7.0
Inko inko 0.16.0
Io Io Programming Language, v. 20151111
Java java 22.0.2 2024-07-16
Javascript node --version
v22.8.0
Javascript deno 1.46.3 (stable, release, x86_64-unknown-linux-gnu)
Javascript bun --version
1.1.26
Julia julia version 1.10.5
Koka Koka 3.1.2, 00:27:36 May 31 2024 (ghc release version)
Kotlin Kotlin version 2.0.20-release-360 (JRE 22.0.2+9-70)
LEAN4 Lean (version 4.11.0, x86_64-unknown-linux-gnu, commit ec3042d94bd1, Release)
LiveScript LiveScript version 1.6.0
Lobster Lobster programming language compiler/runtime (version 2024-05-21T15:49:18-07:00|72fe2da0)
Lua Lua 5.4.7 Copyright (C) 1994-2024 Lua.org, PUC-Rio
Lua LuaJIT 2.1.1725453128 -- Copyright (C) 2005-2023 Mike Pall. https://luajit.org/
Mercury Mercury Compiler, version 22.01.8, on x86_64-pc-linux-gnu
Mojo mojo 24.4.0 (2cb57382)
Nelua Nelua 0.2.0-dev
Nim Nim Compiler Version 2.0.8 [Linux: amd64]
Nit v0.8-3758-g17eaca044
OCaml The OCaml toplevel, version 5.2.0
Odin odin version dev-2024-09:16c5c69a4
Onyx Onyx toolchain version v0.1.12
Pascal Free Pascal Compiler version 3.2.2+dfsg-32 [2024/01/05] for x86_64
Peregrine Peregrine Compiler (C) The Peregrine Organisation, MPL-2.0
Perl This is perl 5, version 40, subversion 0 (v5.40.0) built for x86_64-linux
Php PHP 8.3.11 (cli) (built: Aug 27 2024 19:16:34) (NTS)
Pike Pike v8.0 release 1738 Copyright © 1994-2022 Linköping University
Pinecone Pinecone version 0.5.1
Poly/ML Poly/ML 5.9.1 Release RTS version: X86_64-5.9.1
Pony 0.58.5-0d607b5 [release]
Python Python 3.12.5
R R version 4.4.1 (2024-06-14) -- "Race for Your Life"
Racket Welcome to Racket v8.14 [cs].
Raku Welcome to Rakudo™ v2024.08.
Reason Reason 3.12.0 @
ReScript 11.1.4
Ring Ring version 1.22.0
Ruby ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]
Rune 0.13.4
Rust rustc 1.82.0 (f6e511eec 2024-10-15)
Scala Scala version (default): 3.5.0
Scala sbt script version: 1.10.1
Seed7 SEED7 COMPILER Version 3.2.70 Copyright (c) 1990-2024 Thomas Mertes
Squirrel Squirrel 3.2 stable Copyright (C) 2003-2022 Alberto Demichelis (64 bits)
Swi-Prolog SWI-Prolog version 9.2.7 for x86_64-linux
Swift Swift version 6.0.2 (swift-6.0.2-RELEASE)
V V 0.4.7 9238dd6
Vala Vala 0.56.17
Zig 0.14.0-dev.1472+3929cac15

測定

A

Ada
Sat Sep 14 07:43:17 AM JST 2024
$ 
tarai.adb
with Ada.Text_IO;

procedure Tarai is
  function tarai(x, y, z: Integer) return Integer is
  begin
    if x <= y then
      return y;
    else
      return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
    end if;
  end tarai;

begin
  Ada.Text_IO.Put_Line(Integer'Image(tarai(15, 5, 0)));
end Tarai;
$ gnat-14 --version
GNAT 14.0.1 20240412 (experimental) [master r14-9935-g67e1433a94f]
Copyright (C) 1996-2024, Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ rm tarai.ali; gnat-14 make -o a.out tarai.adb; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
x86_64-linux-gnu-gcc-14 -c tarai.adb
x86_64-linux-gnu-gnatbind-14 -x tarai.ali
x86_64-linux-gnu-gnatlink-14 tarai.ali -o a.out
 15
real:6.97[sec]_user:6.97[sec]_sys:0.00[sec]_Memory:4224[KB]
$ rm tarai.ali; gnat-14 make -O1 -o a.out tarai.adb; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
x86_64-linux-gnu-gcc-14 -c -O1 tarai.adb
x86_64-linux-gnu-gnatbind-14 -x tarai.ali
x86_64-linux-gnu-gnatlink-14 tarai.ali -O1 -o a.out
 15
real:5.61[sec]_user:5.60[sec]_sys:0.00[sec]_Memory:4224[KB]
$ rm tarai.ali; gnat-14 make -O2 -o a.out tarai.adb; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
x86_64-linux-gnu-gcc-14 -c -O2 tarai.adb
x86_64-linux-gnu-gnatbind-14 -x tarai.ali
x86_64-linux-gnu-gnatlink-14 tarai.ali -O2 -o a.out
 15
real:5.34[sec]_user:5.34[sec]_sys:0.00[sec]_Memory:4224[KB]
$ rm tarai.ali; gnat-14 make -O3 -o a.out tarai.adb; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
x86_64-linux-gnu-gcc-14 -c -O3 tarai.adb
x86_64-linux-gnu-gnatbind-14 -x tarai.ali
x86_64-linux-gnu-gnatlink-14 tarai.ali -O3 -o a.out
 15
real:3.13[sec]_user:3.13[sec]_sys:0.00[sec]_Memory:4224[KB]
Algol
Sat Sep  7 03:25:24 PM JST 2024
$ a68g --pretty-print tarai.alg
tarai.alg
PROC tarai = (INT i, j, k) INT:
     IF i <= j
     THEN j
     ELSE tarai (tarai (i - 1, j, k), tarai (j - 1, k, i), tarai (k - 1, i, j))
     FI;
print ((tarai (15, 5, 0), new line))
$ a68g -v | head
Algol 68 Genie 3.1.2
Copyright 2001-2023 Marcel van der Veer <algol68g@xs4all.nl>.

This is free software covered by the GNU General Public License.
There is ABSOLUTELY NO WARRANTY for Algol 68 Genie;
not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

Please report bugs to Marcel van der Veer <algol68g@xs4all.nl>.

$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] a68g tarai.alg
                 +15
real:471.05[sec]_user:471.04[sec]_sys:0.00[sec]_Memory:20864[KB]
Ante
Sat Sep 14 08:45:33 JST 2024
$ 
tarai.an
tarai x y z =
    if x <= y then y
    else tarai ( tarai (x - 1) y z ) ( tarai (y - 1) z x ) ( tarai (z - 1) x y )

print (tarai 15 5 0)
$ ante --version
ante 0.1.1
$ rm tarai; ante -b tarai.an; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:19.91[sec]_user:19.91[sec]_sys:0.00[sec]_Memory:1664[KB]
$ rm tarai; ante -b -O1 tarai.an; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:16.26[sec]_user:16.26[sec]_sys:0.00[sec]_Memory:1536[KB]
$ rm tarai; ante -b -O2 tarai.an; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:18.69[sec]_user:18.69[sec]_sys:0.00[sec]_Memory:1536[KB]
$ rm tarai; ante -b -O3 tarai.an; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:18.70[sec]_user:18.69[sec]_sys:0.00[sec]_Memory:1536[KB]
Arkscript
Sat Sep 14 09:31:14 AM JST 2024
$ arkscript --format tarai.ark
tarai.ark
(let tarai (fun (x y z)
    (if (<= x y)
      y
      (tarai (tarai (- x 1) y z) (tarai (- y 1) z x) (tarai (- z 1) x y)))))

(print (tarai 15 5 0))
$ arkscript --version
4.0.0-3c9e3ab5
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] arkscript tarai.ark
15
real:703.28[sec]_user:703.27[sec]_sys:0.00[sec]_Memory:6016[KB]
$ arkscript -c tarai.ark;\time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] arkscript __arkscript__/tarai.arkc
15
real:695.89[sec]_user:695.87[sec]_sys:0.01[sec]_Memory:5888[KB]
Austral
Sat Sep 14 10:42:22 AM JST 2024
$ 
tarai.aum
module body Tarai is
    function tarai(x: Int32, y: Int32, z: Int32): Int32 is
        if x <= y then
            return y;
        else
            return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
        end if;
    end;
    
    function main(): ExitCode is
        printLn(tarai(15, 5, 0));
        return ExitSuccess();
    end;
end module body.
$ austral --version
0.2.0
$ rm -rf a.out; austral compile tarai.aum --entrypoint=Tarai:main --output=a.out; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:11.69[sec]_user:11.68[sec]_sys:0.00[sec]_Memory:1536[KB]

B

Ballerina
Sat Sep  7 07:22:16 PM JST 2024
$ bal format tarai.bal
modified files:
tarai.bal

format successful.
tarai.bal
import ballerina/io;

public function tarai(int x, int y, int z) returns int {
    if x <= y {
        return y;
    } else {
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
    }
}

public function main() {
    io:println(tarai(15, 5, 0));
}
$ sdk use java 17.0.12-oracle

Using java version 17.0.12-oracle in this shell.
$ bal -v
Ballerina 2201.10.0 (Swan Lake Update 10)
Language specification 2024R1
Update Tool 1.4.3
$ java --version
java 17.0.12 2024-07-16 LTS
Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.12+8-LTS-286, mixed mode, sharing)
$ rm -rf tarai.jar; bal build tarai.bal; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] java -jar tarai.jar
Compiling source
	tarai.bal

Generating executable
	tarai.jar
15
real:11.78[sec]_user:12.00[sec]_sys:0.03[sec]_Memory:63540[KB]

C

C
Fri Sep  6 08:21:19 PM JST 2024
$ clang-format-18 --style="{ BasedOnStyle: Google }" -i tarai.c
tarai.c
#include <stdio.h>

int tarai(int x, int y, int z) {
  if (x <= y) {
    return y;
  } else {
    return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
  }
}

int main(void) {
  printf("%d\n", tarai(15, 5, 0));

  return 0;
}
$ gcc-14 --version
gcc-14 (Homebrew GCC 14.2.0) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ rm -rf a.out; gcc-14 tarai.c -lm; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:6.03[sec]_user:6.03[sec]_sys:0.00[sec]_Memory:1792[KB]
$ rm -rf a.out; gcc-14 -Ofast tarai.c -lm; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:2.57[sec]_user:2.57[sec]_sys:0.00[sec]_Memory:1792[KB]
$ clang-18 --version
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ rm -rf a.out; clang-18 tarai.c -lm; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:5.78[sec]_user:5.77[sec]_sys:0.00[sec]_Memory:1792[KB]
$ rm -rf a.out; clang-18 -Ofast tarai.c -lm; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:4.27[sec]_user:4.27[sec]_sys:0.00[sec]_Memory:1792[KB]
Chez Scheme
Fri Sep 13 08:34:02 PM JST 2024
$ scheme-format -i tarai.ss
tarai.ss
(define tarai
        (lambda (x y z)
         (if (<= x y)
          y
          (tarai (tarai (- x 1) y z) (tarai (- y 1) z x) (tarai (- z 1) x y)))))
(display (tarai 15 5 0))
(newline)
$ chez --version
10.0.0
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] chez --script tarai.ss
15
real:7.10[sec]_user:7.08[sec]_sys:0.01[sec]_Memory:47104[KB]
Chicken
Fri Sep 13 08:38:06 PM JST 2024
$ scheme-format -i tarai.scm
tarai.scm
(define (tarai x y z)
 (if (<= x y)
  y
  (tarai (tarai (- x 1) y z) (tarai (- y 1) z x) (tarai (- z 1) x y))))

(print (tarai 15 5 0))
$ csc -version
CHICKEN
(c) 2008-2022, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 5.4.0 (rev 1a1d1495)
linux-unix-gnu-x86-64 [ 64bit dload ptables ]

$ rm -rf tarai;csc tarai.scm;\time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:69.40[sec]_user:69.12[sec]_sys:0.27[sec]_Memory:18556[KB]
$ rm -rf tarai;csc -O1 tarai.scm;\time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:69.28[sec]_user:68.96[sec]_sys:0.31[sec]_Memory:18556[KB]
$ rm -rf tarai;csc -O2 tarai.scm;\time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:69.23[sec]_user:68.93[sec]_sys:0.30[sec]_Memory:18684[KB]
$ rm -rf tarai;csc -O3 tarai.scm;\time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:64.40[sec]_user:64.12[sec]_sys:0.28[sec]_Memory:18680[KB]
$ rm -rf tarai;csc -O4 tarai.scm;\time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:64.98[sec]_user:64.67[sec]_sys:0.30[sec]_Memory:18680[KB]
Clio
Sat Sep 14 10:59:41 AM JST 2024
$ 
src/main.clio
fn tarai x y z:
  if x <= y: y
  else: tarai (tarai x - 1 y z) (tarai y - 1 z x) (tarai z - 1 x y)

export fn main argv:
  tarai 15 5 0 -> console.log
$ clio --version
0.12.0
$ node --version
v22.8.0
$ rm -rf build; clio build; cd build
Info: Compiling from "clio.toml"
Info: Creating build for target "js"
✔ Compiling from source...
✔ Copying over the resource files...
✔ Adding Clio start script...
✔ Installing npm dependencies (this may take a while)...
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] node .clio/index.js
15
real:8.43[sec]_user:8.86[sec]_sys:0.46[sec]_Memory:166772[KB]
$ bun --version
1.1.26
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] bun .clio/index.js
[bun] Warning: async_hooks.createHook is not implemented in Bun. Hooks can still be created but will never be called.
15
real:14.63[sec]_user:16.76[sec]_sys:30.69[sec]_Memory:172752[KB]
Clojure
Fri Sep  6 08:44:13 PM JST 2024
$ cljfmt src/tarai/core.clj
src/tarai/core.clj
(ns tarai.core
  (:gen-class))

(defn tarai [x y z]
  (do
    (if (<= x y)
      y
      (tarai
       (tarai (- x 1) y z)
       (tarai (- y 1) z x)
       (tarai (- z 1) x y)))))

(defn -main
  [& args]
  (prn (tarai 15 5 0)))
$ sdk use java 22.0.2-oracle

Using java version 22.0.2-oracle in this shell.
$ lein --version
Leiningen 2.11.2 on Java 22.0.2 Java HotSpot(TM) 64-Bit Server VM
$ java --version
java 22.0.2 2024-07-16
Java(TM) SE Runtime Environment (build 22.0.2+9-70)
Java HotSpot(TM) 64-Bit Server VM (build 22.0.2+9-70, mixed mode, sharing)
$ lein clean; lein uberjar; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] java -jar ./target/uberjar/tarai-0.1.0-SNAPSHOT-standalone.jar
Compiling tarai.core
Created /home/freezer/workspace/clojure/tarai/target/uberjar/tarai-0.1.0-SNAPSHOT.jar
Created /home/freezer/workspace/clojure/tarai/target/uberjar/tarai-0.1.0-SNAPSHOT-standalone.jar
15
real:8.94[sec]_user:9.61[sec]_sys:0.07[sec]_Memory:91604[KB]
Common Lisp
Sun Sep 15 10:12:39 AM JST 2024
$ scheme-format -i tarai.lsp
tarai.lsp
(defun tarai
       (x y z)
       (if (<= x y)
        y
        (tarai (tarai (- x 1) y z) (tarai (- y 1) z x) (tarai (- z 1) x y))))
(print (tarai 15 5 0))
$ clisp --version
GNU CLISP 2.49.92 (2018-02-18) (built on a969dca806f5 [172.18.0.2])
Software: GNU C 11.2.0 
gcc-11 -g -O2 -W -Wswitch -Wcomment -Wpointer-arith -Wreturn-type -Wmissing-declarations -Wimplicit -Wno-sign-compare -Wno-format-nonliteral -Wno-shift-negative-value -O -fwrapv -fno-strict-aliasing -DNO_ASM -DENABLE_UNICODE -DDYNAMIC_MODULES  libgnu.a  -lreadline -lncurses   -lsigsegv   
SAFETY=0 HEAPCODES ONE_FREE_BIT_HEAPCODES WIDE_HARD GENERATIONAL_GC SPVW_BLOCKS SPVW_MIXED TRIVIALMAP_MEMORY
libsigsegv 2.14
libreadline 8.1
Features: 
(REGEXP WILDCARD SYSCALLS I18N LOOP COMPILER CLOS MOP CLISP ANSI-CL COMMON-LISP LISP=CL INTERPRETER LOGICAL-PATHNAMES SOCKETS GENERIC-STREAMS
 SCREEN GETTEXT UNICODE BASE-CHAR=CHARACTER WORD-SIZE=64 PC386 UNIX)
C Modules: (clisp i18n syscalls regexp)
Installation directory: /home/linuxbrew/.linuxbrew/Cellar/clisp/2.49.92_1/lib/clisp-2.49.92/
User language: ENGLISH
Machine: X86_64 (X86_64) beelinkeq12 [127.0.1.1]
$ rm -rf tarai.fas; clisp -c tarai.lsp; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] clisp tarai.fas
  i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo
  I I I I I I I      8     8   8           8     8     o  8    8
  I  \ `+' /  I      8         8           8     8        8    8
   \  `-+-'  /       8         8           8      ooooo   8oooo
    `-__|__-'        8         8           8           8  8
        |            8     o   8           8     o     8  8
  ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8

Welcome to GNU CLISP 2.49.92 (2018-02-18) <http://clisp.org/>

Copyright (c) Bruno Haible, Michael Stoll 1992-1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2018

Type :h and hit Enter for context help.

;; Compiling file /home/freezer/workspace/clisp/tarai/tarai.lsp ...
;; Wrote file /home/freezer/workspace/clisp/tarai/tarai.fas
0 errors, 0 warnings
Bye.

15 
real:105.04[sec]_user:105.03[sec]_sys:0.00[sec]_Memory:9728[KB]
COBOL
Sat Sep 21 11:07:08 AM JST 2024
$ 
tarai.cbl
       IDENTIFICATION DIVISION.
       FUNCTION-ID. TARAI.
       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01 x1 PIC S9(8).
       01 y1 PIC S9(8).
       01 z1 PIC S9(8).
       LINKAGE SECTION.
       01 x0 PIC S9(8).
       01 y0 PIC S9(8).
       01 z0 PIC S9(8).
       01 r  PIC S9(8).
       PROCEDURE DIVISION USING x0 y0 z0 RETURNING r.
       IF x0 <= y0 THEN
           COMPUTE r = y0
       ELSE
           COMPUTE x1 = x0 - 1
           COMPUTE y1 = y0 - 1
           COMPUTE z1 = z0 - 1
           COMPUTE r =
               FUNCTION TARAI (
                   FUNCTION TARAI (x1 y0 z0)
                   FUNCTION TARAI (y1 z0 x0)
                   FUNCTION TARAI (z1 x0 y0)
               )
       END-IF.
       EXIT FUNCTION.
       END FUNCTION TARAI.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. MAIN.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           FUNCTION TARAI.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 xn PIC S9(8).
       01 yn PIC S9(8).
       01 zn PIC S9(8).
       PROCEDURE DIVISION.
           COMPUTE xn = 15.
           COMPUTE yn = 5.
           COMPUTE zn = 0.
           DISPLAY FUNCTION TARAI (xn yn zn).
           STOP RUN.
$ cobc --version
cobc (GnuCOBOL) 3.1.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
Built     Apr 14 2024 07:59:15
Packaged  Dec 23 2020 12:04:58 UTC
C version "13.2.0"
$ rm -rf a.out; cobc -x -free -o ./a.out ./tarai.cbl; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
+00000015
real:2212.79[sec]_user:2212.73[sec]_sys:0.03[sec]_Memory:7424[KB]
$ rm -rf a.out; cobc -x -free -O2 -o ./a.out ./tarai.cbl; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
+00000015
real:2164.89[sec]_user:2164.76[sec]_sys:0.00[sec]_Memory:7808[KB]
Concurnas
Sat Sep 14 11:14:35 AM JST 2024
$ 
tarai.conc
def tarai(x int, y int, z int) int {
  if (x > y) {
    return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
  } else { 
    return y
  }
}

System.out.println(tarai(15, 5, 0))!
$ sdk use java 11.0.24-amzn

Using java version 11.0.24-amzn in this shell.
$ java --version
openjdk 11.0.24 2024-07-16 LTS
OpenJDK Runtime Environment Corretto-11.0.24.8.1 (build 11.0.24+8-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.24.8.1 (build 11.0.24+8-LTS, mixed mode)
$ concc tarai.conc; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] conc tarai
Finished compilation of: /home/freezer/workspace/concurnas/tarai/tarai.conc -> /home/freezer/workspace/concurnas/tarai/tarai$tarai$$Lambda0.class [tarai$tarai$$Lambda0], /home/freezer/workspace/concurnas/tarai/tarai.class [tarai]

15

real:20.87[sec]_user:26.57[sec]_sys:0.29[sec]_Memory:215152[KB]
C++
Fri Sep  6 08:38:29 PM JST 2024
$ clang-format-18 --style="{ BasedOnStyle: Google }" -i tarai.cpp
tarai.cpp
#include <iostream>

int tarai(int x, int y, int z) {
  if (x <= y) {
    return y;
  } else {
    return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
  }
}

int main(void) {
  std::cout << tarai(15, 5, 0) << std::endl;

  return 0;
}
$ g++-14 --version
g++-14 (Homebrew GCC 14.2.0) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ rm -rf a.out; g++-14 tarai.cpp; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:6.74[sec]_user:6.74[sec]_sys:0.00[sec]_Memory:3584[KB]
$ rm -rf a.out; g++-14 -Ofast tarai.cpp; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:2.56[sec]_user:2.56[sec]_sys:0.00[sec]_Memory:3584[KB]
$ clang++-18 --version
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ rm -rf a.out; clang++-18 tarai.cpp; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:5.83[sec]_user:5.82[sec]_sys:0.00[sec]_Memory:3584[KB]
$ rm -rf a.out; clang++-18 -Ofast tarai.cpp; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:4.27[sec]_user:4.27[sec]_sys:0.00[sec]_Memory:3584[KB]
Crystal
Fri Sep  6 08:50:12 PM JST 2024
$ crystal tool format src/tarai.cr
Format ./src/tarai.cr
src/tarai.cr
module Tarai
  def tarai(x : Int32, y : Int32, z : Int32)
    if x <= y
      return y
    else
      return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    end
  end
end

include Tarai

puts tarai(15, 5, 0)
$ crystal --version
Crystal 1.13.2 [879ec1247] (2024-08-20)

LLVM: 18.1.6
Default target: x86_64-unknown-linux-gnu
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] crystal run src/tarai.cr
15
real:7.27[sec]_user:7.04[sec]_sys:0.36[sec]_Memory:251748[KB]
$ rm -rf tarai; crystal build src/tarai.cr; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:5.91[sec]_user:5.91[sec]_sys:0.00[sec]_Memory:4096[KB]
$ rm -rf tarai; crystal build --release src/tarai.cr; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:4.27[sec]_user:4.27[sec]_sys:0.00[sec]_Memory:3200[KB]
$ rm -rf tarai; crystal build -O1 src/tarai.cr; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:3.87[sec]_user:3.87[sec]_sys:0.00[sec]_Memory:3584[KB]
$ rm -rf tarai; crystal build -O2 src/tarai.cr; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:3.81[sec]_user:3.81[sec]_sys:0.00[sec]_Memory:3584[KB]
$ rm -rf tarai; crystal build -O3 src/tarai.cr; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:4.87[sec]_user:4.87[sec]_sys:0.00[sec]_Memory:3584[KB]
C#
Fri Sep  6 08:57:23 PM JST 2024
$ dotnet format style
Program.cs
using System;

namespace ConsoleApp {
  class Program {
    static int tarai(int x, int y, int z) {
      if (x <= y) {
        return y;
      } else {
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
      }
    }
    static void Main() {
      Console.WriteLine(tarai(15, 5, 0));
    }
  }
}

$ dotnet --version
8.0.401
$ dotnet clean; dotnet build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] dotnet run
Build started 9/6/2024 8:57:28 PM.
     1>Project "/home/freezer/workspace/csharp/tarai/tarai.csproj" on node 1 (Clean target(s)).
     1>CoreClean:
         Deleting file "/home/freezer/workspace/csharp/tarai/bin/Debug/net8.0/tarai".
         Deleting file "/home/freezer/workspace/csharp/tarai/bin/Debug/net8.0/tarai.deps.json".
         Deleting file "/home/freezer/workspace/csharp/tarai/bin/Debug/net8.0/tarai.runtimeconfig.json".
         Deleting file "/home/freezer/workspace/csharp/tarai/bin/Debug/net8.0/tarai.dll".
         Deleting file "/home/freezer/workspace/csharp/tarai/bin/Debug/net8.0/tarai.pdb".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.GeneratedMSBuildEditorConfig.editorconfig".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.AssemblyInfoInputs.cache".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.AssemblyInfo.cs".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.csproj.CoreCompileInputs.cache".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.dll".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/refint/tarai.dll".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.pdb".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.genruntimeconfig.cache".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/ref/tarai.dll".
     1>Done Building Project "/home/freezer/workspace/csharp/tarai/tarai.csproj" (Clean target(s)).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.45
  Determining projects to restore...
  All projects are up-to-date for restore.
  tarai -> /home/freezer/workspace/csharp/tarai/bin/Debug/net8.0/tarai.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.85
15
real:10.66[sec]_user:11.74[sec]_sys:0.31[sec]_Memory:186692[KB]
$ dotnet clean; dotnet publish; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./bin/Release/net8.0/tarai
Build started 9/6/2024 8:57:43 PM.
     1>Project "/home/freezer/workspace/csharp/tarai/tarai.csproj" on node 1 (Clean target(s)).
     1>CoreClean:
         Deleting file "/home/freezer/workspace/csharp/tarai/bin/Debug/net8.0/tarai".
         Deleting file "/home/freezer/workspace/csharp/tarai/bin/Debug/net8.0/tarai.deps.json".
         Deleting file "/home/freezer/workspace/csharp/tarai/bin/Debug/net8.0/tarai.runtimeconfig.json".
         Deleting file "/home/freezer/workspace/csharp/tarai/bin/Debug/net8.0/tarai.dll".
         Deleting file "/home/freezer/workspace/csharp/tarai/bin/Debug/net8.0/tarai.pdb".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.GeneratedMSBuildEditorConfig.editorconfig".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.AssemblyInfoInputs.cache".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.AssemblyInfo.cs".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.csproj.CoreCompileInputs.cache".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.dll".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/refint/tarai.dll".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.pdb".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/tarai.genruntimeconfig.cache".
         Deleting file "/home/freezer/workspace/csharp/tarai/obj/Debug/net8.0/ref/tarai.dll".
     1>Done Building Project "/home/freezer/workspace/csharp/tarai/tarai.csproj" (Clean target(s)).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.45
  Determining projects to restore...
  All projects are up-to-date for restore.
  tarai -> /home/freezer/workspace/csharp/tarai/bin/Release/net8.0/tarai.dll
  tarai -> /home/freezer/workspace/csharp/tarai/bin/Release/net8.0/publish/
15
real:3.13[sec]_user:3.11[sec]_sys:0.00[sec]_Memory:28596[KB]
Cyber
Fri Sep  6 09:22:30 PM JST 2024
$ 
tarai.cy
func tarai(x int, y int, z int) int:
    if x <= y:
        return y
    else:
        return tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y))

print(tarai(15, 5, 0))
$ cyber version
Cyber 0.3 build-0-13a7bef
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] cyber tarai.cy
15
real:29.97[sec]_user:29.97[sec]_sys:0.00[sec]_Memory:3712[KB]

D

D
Sat Sep  7 07:49:21 PM JST 2024
$ dfmt -i tarai.d
tarai.d
import std.stdio;

int tarai(int x, int y, int z)
{
    if (x <= y)
        return y;
    else
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
}

void main()
{
    writeln(tarai(15, 5, 0));
}
$ gdc-14 --version
gdc-14 (Ubuntu 14-20240412-0ubuntu1) 14.0.1 20240412 (experimental) [master r14-9935-g67e1433a94f]
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ rm -rf a.out; gdc-14 -o a.out tarai.d; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:6.58[sec]_user:6.57[sec]_sys:0.00[sec]_Memory:6528[KB]
$ rm -rf a.out; gdc-14 -Ofast -o a.out tarai.d; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:2.43[sec]_user:2.43[sec]_sys:0.00[sec]_Memory:6528[KB]
$ ldc2 --version | head
LDC - the LLVM D compiler (1.39.0):
  based on DMD v2.109.1 and LLVM 18.1.8
  built with LDC - the LLVM D compiler (1.39.0)
  Default target: x86_64-unknown-linux-gnu
  Host CPU: alderlake
  http://dlang.org - http://wiki.dlang.org/LDC


  Registered Targets:
    aarch64     - AArch64 (little endian)
$ rm -rf tarai; ldc2 tarai.d; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:5.13[sec]_user:5.13[sec]_sys:0.00[sec]_Memory:2688[KB]
$ rm -rf tarai; ldc2 --O3 tarai.d; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:4.27[sec]_user:4.27[sec]_sys:0.00[sec]_Memory:2688[KB]
Dart
Sat Sep 14 12:09:33 PM JST 2024
$ dart format tarai.dart
Formatted 1 file (0 changed) in 0.11 seconds.
tarai.dart
int tarai(int x, int y, int z) {
  if (x <= y) {
    return y;
  } else {
    return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
  }
}

main() {
  print(tarai(15, 5, 0));
}
$ dart --version
Dart SDK version: 3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "linux_x64"
$ dart --disable-analytics
Analytics reporting disabled. In order to enable it, run: dart --enable-analytics
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] dart run tarai.dart
15
real:7.88[sec]_user:8.04[sec]_sys:0.09[sec]_Memory:154300[KB]
$ dart compile exe tarai.dart; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai.exe
Generated: /home/freezer/workspace/dart/tarai/tarai.exe
15
real:5.23[sec]_user:5.23[sec]_sys:0.00[sec]_Memory:6272[KB]
$ dart compile jit-snapshot tarai.dart; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] dart run tarai.jit
Compiling tarai.dart to jit-snapshot file tarai.jit.
15
15
real:7.51[sec]_user:7.55[sec]_sys:0.04[sec]_Memory:72140[KB]
$ dart compile js tarai.dart -o tarai.js; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] node tarai.js
Compiled 10,132,429 input bytes (5,140,333 characters source) to 97,655 characters JavaScript in 0.73 seconds using 0.000 MB of memory
15
real:10.43[sec]_user:10.42[sec]_sys:0.01[sec]_Memory:49404[KB]
Dictu
Sat Sep 14 12:44:06 PM JST 2024
$ 
tarai.du
def tarai(x, y, z) {
    if (x <= y)
        return y;
    else 
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
}

print(tarai(15, 5, 0));
$ dictu --version
Dictu Version: 0.30.0
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] dictu tarai.du
15
real:107.42[sec]_user:107.41[sec]_sys:0.00[sec]_Memory:8576[KB]
Draco
Sat Sep 14 11:40:28 AM JST 2024
$ 
main.draco
import System.Console;

func main() =
  WriteLine(tarai(15, 5, 0));

func tarai(x: int32, y: int32, z: int32): int32 =
  if (x <= y) y
  else tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
$ dotnet --version
8.0.401
$ dotnet clean; dotnet build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] dotnet run
Build started 9/14/2024 11:40:29 AM.

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.46
  Determining projects to restore...
  All projects are up-to-date for restore.
  tarai -> /home/freezer/workspace/draco/tarai/bin/Debug/net8.0/tarai.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.58
15
real:11.30[sec]_user:12.56[sec]_sys:0.28[sec]_Memory:184296[KB]
$ dotnet clean; dotnet publish; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] bin/Release/net8.0/tarai
Build started 9/14/2024 11:40:44 AM.
     1>Project "/home/freezer/workspace/draco/tarai/tarai.dracoproj" on node 1 (Clean target(s)).
     1>CoreClean:
         Deleting file "/home/freezer/workspace/draco/tarai/bin/Debug/net8.0/tarai".
         Deleting file "/home/freezer/workspace/draco/tarai/bin/Debug/net8.0/tarai.deps.json".
         Deleting file "/home/freezer/workspace/draco/tarai/bin/Debug/net8.0/tarai.runtimeconfig.json".
         Deleting file "/home/freezer/workspace/draco/tarai/bin/Debug/net8.0/tarai.dll".
         Deleting file "/home/freezer/workspace/draco/tarai/bin/Debug/net8.0/tarai.pdb".
         Deleting file "/home/freezer/workspace/draco/tarai/obj/Debug/net8.0/tarai.dracoproj.CoreCompileInputs.cache".
         Deleting file "/home/freezer/workspace/draco/tarai/obj/Debug/net8.0/tarai.dll".
         Deleting file "/home/freezer/workspace/draco/tarai/obj/Debug/net8.0/tarai.pdb".
         Deleting file "/home/freezer/workspace/draco/tarai/obj/Debug/net8.0/tarai.genruntimeconfig.cache".
     1>Done Building Project "/home/freezer/workspace/draco/tarai/tarai.dracoproj" (Clean target(s)).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.48
  Determining projects to restore...
  All projects are up-to-date for restore.
  tarai -> /home/freezer/workspace/draco/tarai/bin/Release/net8.0/tarai.dll
  tarai -> /home/freezer/workspace/draco/tarai/bin/Release/net8.0/publish/
15
real:8.62[sec]_user:8.60[sec]_sys:0.00[sec]_Memory:28632[KB]

E

Elixir
Sun Sep  8 07:29:26 AM JST 2024
$ mix format lib/tarai.ex
lib/tarai.ex
defmodule Tarai do
  def tarai(x, y, z) do
    if x <= y do
      y
    else
      tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    end
  end

  def main(_) do
    IO.puts(Tarai.tarai(15, 5, 0))
  end
end
$ elixir --version
Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit:ns]

Elixir 1.17.2 (compiled with Erlang/OTP 27)
$ mix --version
Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit:ns]

Mix 1.17.2 (compiled with Erlang/OTP 27)
$ rm -rf tarai; mix clean; mix escript.build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
Compiling 1 file (.ex)
Generated tarai app
Generated escript tarai with MIX_ENV=dev
15
real:10.83[sec]_user:10.88[sec]_sys:0.12[sec]_Memory:67064[KB]
Erlang
Sun Sep  8 07:11:50 AM JST 2024
$ efmt -w src/tarai.erl
[2024-09-07T22:11:50Z INFO  efmt] All files were formatted correctly!
src/tarai.erl
-module(tarai).

-export([main/1]).


main(_) ->
    io:format("~p~n", [tarai(15, 5, 0)]),
    erlang:halt(0).


tarai(X, Y, _) when X =< Y -> Y;
tarai(X, Y, Z) -> tarai(tarai(X - 1, Y, Z), tarai(Y - 1, Z, X), tarai(Z - 1, X, Y)).
$ rebar3 --version
rebar 3.24.0 on Erlang/OTP 27 Erts 15.0.1
$ rebar3 escriptize; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./_build/default/bin/tarai
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling tarai
===> Building escript for tarai...
15
real:7.97[sec]_user:8.01[sec]_sys:0.12[sec]_Memory:55688[KB]

F

Fantom
Sat Sep 14 05:14:27 PM JST 2024
$ 
tarai.fan
class Tarai {
  static Int tarai(Int x, Int y, Int z) {
    if (x <= y) {
      return y;
    } else {
      return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
    }
  }
  static Void main() {
    echo(tarai(15, 5, 0));
  }
}
$ fan -version
Fantom Launcher
Copyright (c) 2006-2023, Brian Frank and Andy Frank
Licensed under the Academic Free License version 3.0

Java Runtime:
  java.version:    22.0.2
  java.vm.name:    OpenJDK 64-Bit Server VM
  java.vm.vendor:  Homebrew
  java.vm.version: 22.0.2
  java.home:       /home/linuxbrew/.linuxbrew/Cellar/openjdk/22.0.2/libexec
  fan.platform:    linux-x86_64
  fan.version:     1.0.80
  fan.env:         sys::BootEnv
  fan.home:        /home/linuxbrew/.linuxbrew/Cellar/fantom/1.0.80/libexec

Env Path:
  /home/linuxbrew/.linuxbrew/Cellar/fantom/1.0.80/libexec (work) (home)


$ java --version
java 22.0.2 2024-07-16
Java(TM) SE Runtime Environment (build 22.0.2+9-70)
Java HotSpot(TM) 64-Bit Server VM (build 22.0.2+9-70, mixed mode, sharing)
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] fan tarai.fan
15
real:4.81[sec]_user:5.88[sec]_sys:0.08[sec]_Memory:106044[KB]
Flix
Sat Sep 14 13:37:57 JST 2024
$ 
src/Main.flix
def main(): Unit \ IO =
    println(tarai(15, 5, 0))

def tarai(x: Int32, y: Int32, z: Int32): Int32 =
    if (x <= y) y
    else tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
$ flix --version
The Flix Programming Language 0.50.0
$ java --version
java 22.0.2 2024-07-16
Java(TM) SE Runtime Environment (build 22.0.2+9-70)
Java HotSpot(TM) 64-Bit Server VM (build 22.0.2+9-70, mixed mode, sharing)
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] flix run
Found `flix.toml`. Checking dependencies...
Resolving Flix dependencies...
Downloading Flix dependencies...
Resolving Maven dependencies...
  Running Maven dependency resolver.
Downloading external jar dependencies...
Dependency resolution completed.
15                                                                              
real:50.25[sec]_user:72.13[sec]_sys:1.17[sec]_Memory:2095592[KB]
$ flix build-jar; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] java -jar artifact/tarai.jar src/Main.flix
Found `flix.toml`. Checking dependencies...
Resolving Flix dependencies...
Downloading Flix dependencies...
Resolving Maven dependencies...
  Running Maven dependency resolver.
Downloading external jar dependencies...
Dependency resolution completed.
15
real:20.91[sec]_user:20.73[sec]_sys:0.26[sec]_Memory:601000[KB]
Fortran
Fri Sep  6 09:08:18 PM JST 2024
$ fprettify tarai.f90
tarai.f90
recursive function tarai(x, y, z) result(ret)
   integer, intent(in) :: x, y, z
   integer :: ret

   if (x <= y) then
      ret = y
   else
      ret = tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
   end if
end function tarai

program main
   use, intrinsic :: iso_fortran_env
   integer :: tarai

   print *, tarai(15, 5, 0)
end program main
$ gfortran --version
GNU Fortran (Homebrew GCC 14.2.0) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ rm -rf a.out; gfortran -o a.out tarai.f90; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
          15
real:7.09[sec]_user:7.09[sec]_sys:0.00[sec]_Memory:2432[KB]
$ rm -rf a.out; gfortran -Ofast -o a.out tarai.f90; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
          15
real:3.07[sec]_user:3.07[sec]_sys:0.00[sec]_Memory:2432[KB]
F#
Fri Sep  6 11:53:13 PM JST 2024
$ dotnet fantomas Program.fs
Program.fs was unchanged.
Program.fs
let rec tarai x y z =
    if x <= y then
        y
    else
        tarai (tarai (x - 1) y z) (tarai (y - 1) z x) (tarai (z - 1) x y)

printfn "%d" (tarai 15 5 0)
$ dotnet --version
8.0.401
$ dotnet clean; dotnet build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] dotnet run
Build started 9/6/2024 11:53:14 PM.

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.45
  Determining projects to restore...
  All projects are up-to-date for restore.
  tarai -> /home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/tarai.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.49
15
real:7.59[sec]_user:7.88[sec]_sys:0.16[sec]_Memory:172224[KB]
$ dotnet clean; dotnet publish; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./bin/Release/net8.0/tarai
Build started 9/6/2024 11:53:25 PM.
     1>Project "/home/freezer/workspace/fsharp/tarai/tarai.fsproj" on node 1 (Clean target(s)).
     1>CoreClean:
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/tarai".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/tarai.deps.json".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/tarai.runtimeconfig.json".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/tarai.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/tarai.pdb".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/FSharp.Core.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/cs/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/de/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/es/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/fr/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/it/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/ja/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/ko/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/pl/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/pt-BR/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/ru/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/tr/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/zh-Hans/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/bin/Debug/net8.0/zh-Hant/FSharp.Core.resources.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/obj/Debug/net8.0/tarai.fsproj.AssemblyReference.cache".
         Deleting file "/home/freezer/workspace/fsharp/tarai/obj/Debug/net8.0/tarai.AssemblyInfoInputs.cache".
         Deleting file "/home/freezer/workspace/fsharp/tarai/obj/Debug/net8.0/tarai.AssemblyInfo.fs".
         Deleting file "/home/freezer/workspace/fsharp/tarai/obj/Debug/net8.0/tarai.fsproj.CoreCompileInputs.cache".
         Deleting file "/home/freezer/workspace/fsharp/tarai/obj/Debug/net8.0/tarai.fsproj.Up2Date".
         Deleting file "/home/freezer/workspace/fsharp/tarai/obj/Debug/net8.0/tarai.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/obj/Debug/net8.0/refint/tarai.dll".
         Deleting file "/home/freezer/workspace/fsharp/tarai/obj/Debug/net8.0/tarai.pdb".
         Deleting file "/home/freezer/workspace/fsharp/tarai/obj/Debug/net8.0/tarai.genruntimeconfig.cache".
         Deleting file "/home/freezer/workspace/fsharp/tarai/obj/Debug/net8.0/ref/tarai.dll".
     1>Done Building Project "/home/freezer/workspace/fsharp/tarai/tarai.fsproj" (Clean target(s)).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.46
  Determining projects to restore...
  All projects are up-to-date for restore.
  tarai -> /home/freezer/workspace/fsharp/tarai/bin/Release/net8.0/tarai.dll
  tarai -> /home/freezer/workspace/fsharp/tarai/bin/Release/net8.0/publish/
15
real:5.59[sec]_user:5.56[sec]_sys:0.01[sec]_Memory:33720[KB]

G

Gambit
Sun Sep 22 06:14:32 PM JST 2024
$ scheme-format -i tarai.scm
tarai.scm
(define (tarai x y z)
 (if (<= x y)
  y
  (tarai (tarai (- x 1) y z) (tarai (- y 1) z x) (tarai (- z 1) x y))))

(display (tarai 15 5 0))
(newline)
$ gsc -v
v4.9.5 20230726044844 x86_64-pc-linux-gnu "./configure '--prefix=/home/linuxbrew/.linuxbrew/Cellar/gambit-scheme/4.9.5' '--docdir=/home/linuxbrew/.linuxbrew/Cellar/gambit-scheme/4.9.5/share/doc/gambit-scheme' '--infodir=/home/linuxbrew/.linuxbrew/Cellar/gambit-scheme/4.9.5/share/info' '--enable-single-host' '--enable-default-runtime-options=f8,-8,t8' '--enable-openssl' 'CC=gcc-11' 'CXX=g++-11'"
$ rm -rf tarai;gsc -exe tarai.scm;\time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:16.67[sec]_user:16.67[sec]_sys:0.00[sec]_Memory:11520[KB]
Gauche
Fri Sep 13 08:48:27 PM JST 2024
$ scheme-format -i tarai.scm
tarai.scm
(define (main args)
 (print (tarai 15 5 0)))

(define (tarai x y z)
 (if (<= x y)
  y
  (tarai (tarai (- x 1) y z) (tarai (- y 1) z x) (tarai (- z 1) x y))))
$ gosh -V
Gauche scheme shell, version 0.9.15 [utf-8,pthreads], x86_64-pc-linux-gnu
(version "0.9.15")
(command "gosh")
(scheme.id gauche)
(languages scheme r5rs r7rs)
(encodings utf-8)
(website "https://practical-scheme.net/gauche")
(build.platform "x86_64-pc-linux-gnu")
(build.configure "--disable-debug" "--disable-dependency-tracking" "--prefix=/home/linuxbrew/.linuxbrew/Cellar/gauche/0.9.15" "--libdir=/home/linuxbrew/.linuxbrew/Cellar/gauche/0.9.15/lib" "--enable-multibyte=utf-8" "--with-ca-bundle=/home/linuxbrew/.linuxbrew/share/ca-certificates/cacert.pem" "CC=gcc-11")
(scheme.path "/home/linuxbrew/.linuxbrew/Cellar/gauche/0.9.15/share/gauche-0.98/site/lib" "/home/linuxbrew/.linuxbrew/Cellar/gauche/0.9.15/share/gauche-0.98/0.9.15/lib")
(threads pthreads)
(gauche.net.tls mbedtls)
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] gosh tarai.scm
15
Command exited with non-zero status 70
real:73.39[sec]_user:73.39[sec]_sys:0.00[sec]_Memory:16128[KB]
Gleam
Sat Sep 14 05:34:41 PM JST 2024
$ gleam format src/tarai.gleam
src/tarai.gleam
import gleam/io

pub fn main() {
  io.debug(tarai(15, 5, 0))
}

pub fn tarai(x: Int, y: Int, z: Int) -> Int {
  case x <= y {
    True -> y
    _ -> tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
  }
}
$ gleam --version
gleam 1.4.1
$ gleam clean; gleam build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] gleam run
Downloading packages
 Downloaded 2 packages in 0.01s
  Compiling gleam_stdlib
  Compiling gleeunit
  Compiling tarai
   Compiled in 1.19s
   Compiled in 0.01s
    Running tarai.main
15
real:10.70[sec]_user:10.72[sec]_sys:0.05[sec]_Memory:42912[KB]
Go
Fri Sep  6 11:58:44 PM JST 2024
$ go fmt
main.go
package main

import "fmt"

func tarai(x, y, z int) int {
	if x <= y {
		return y
	} else {
		return tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y))
	}
}

func main() {
	fmt.Println(tarai(15, 5, 0))
}
$ go version
go version go1.23.0 linux/amd64
$ rm -rf tarai; go build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:5.31[sec]_user:5.31[sec]_sys:0.00[sec]_Memory:1536[KB]
Gravity
Sat Sep 14 05:46:19 PM JST 2024
$ 
tarai.gravity
func tarai(x, y, z) {
    if (x <= y) return y;
    else return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
}

func main() {
    System.print(tarai(15, 5, 0));
}
$ gravity --version
Gravity version 0.8.5 (Jul 22 2021)
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] gravity tarai.gravity
15
RESULT: NULL (in 145051.7561 ms)

real:145.05[sec]_user:145.04[sec]_sys:0.00[sec]_Memory:2560[KB]
Groovy
Sat Sep  7 12:00:47 AM JST 2024

Using java version 17.0.12-oracle in this shell.
$ npm-groovy-lint --fix tarai.groovy

npm-groovy-lint results in 1 linted files:
┌─────────┬───────────┬─────────────┬─────────────┬─────────────────┐
│ (index) │ Severity  │ Total found │ Total fixed │ Total remaining │
├─────────┼───────────┼─────────────┼─────────────┼─────────────────┤
│ 0       │ 'Error'   │ 0           │ 0           │ 0               │
│ 1       │ 'Warning' │ 0           │ 0           │ 0               │
│ 2       │ 'Info'    │ 0           │ 0           │ 0               │
└─────────┴───────────┴─────────────┴─────────────┴─────────────────┘
tarai.groovy
int tarai(int x, int y, int z) {
    if (x <= y) {
        y
    } else {
        tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    }
}

public static void main(_) {
    println tarai(15, 5, 0)
}
$ sdk use java 22.0.2-oracle

Using java version 22.0.2-oracle in this shell.
$ groovy --version
Groovy Version: 4.0.22 JVM: 22.0.2 Vendor: Oracle Corporation OS: Linux
$ java --version
java 22.0.2 2024-07-16
Java(TM) SE Runtime Environment (build 22.0.2+9-70)
Java HotSpot(TM) 64-Bit Server VM (build 22.0.2+9-70, mixed mode, sharing)
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] groovy tarai.groovy
15
real:18.20[sec]_user:20.73[sec]_sys:0.34[sec]_Memory:603796[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] groovy --compile-static tarai.groovy
15
real:5.80[sec]_user:8.43[sec]_sys:0.17[sec]_Memory:170424[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] groovy --type-checked tarai.groovy
15
real:18.51[sec]_user:21.69[sec]_sys:0.38[sec]_Memory:710764[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] groovy --compile-static --type-checked tarai.groovy
15
real:5.83[sec]_user:8.64[sec]_sys:0.15[sec]_Memory:174848[KB]
Guile
Fri Sep 13 08:53:07 PM JST 2024
$ scheme-format -i tarai.scm
tarai.scm
(define (tarai x y z)
 (if (<= x y)
  y
  (tarai (tarai (- x 1) y z) (tarai (- y 1) z x) (tarai (- z 1) x y))))

(display (tarai 15 5 0))
(newline)
$ guile -v
guile (GNU Guile) 3.0.10
Copyright (C) 2024 Free Software Foundation, Inc.

License LGPLv3+: GNU LGPL 3 or later <http://gnu.org/licenses/lgpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] guile -s tarai.scm
;;; note: source file /home/freezer/workspace/guile/tarai/tarai.scm
;;;       newer than compiled /home/freezer/.cache/guile/ccache/3.0-LE-8-4.7/home/freezer/workspace/guile/tarai/tarai.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/freezer/workspace/guile/tarai/tarai.scm
;;; compiled /home/freezer/.cache/guile/ccache/3.0-LE-8-4.7/home/freezer/workspace/guile/tarai/tarai.scm.go
15
real:21.25[sec]_user:21.18[sec]_sys:0.03[sec]_Memory:33024[KB]

H

Haskell
Sat Sep  7 12:07:09 AM JST 2024
$ fourmolu -i app/Main.hs
app/Main.hs
{-# LANGUAGE TemplateHaskell #-}

module Main where

tarai :: Int -> Int -> Int -> Int
tarai x y z
    {-
    \| x <= y    = y
    -}
    | x `seq` y `seq` z `seq` x <= y = y
    | otherwise = tarai (tarai (x - 1) y z) (tarai (y - 1) z x) (tarai (z - 1) x y)

main :: IO ()
main = print $ tarai 15 5 0
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.4.8
$ cabal clean; cabal build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./dist-newstyle/build/x86_64-linux/ghc-9.4.8/tarai-0.1.0.0/x/tarai/build/tarai/tarai
Resolving dependencies...
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
 - tarai-0.1.0.0 (exe:tarai) (first run)
Configuring executable 'tarai' for tarai-0.1.0.0..
Preprocessing executable 'tarai' for tarai-0.1.0.0..
Building executable 'tarai' for tarai-0.1.0.0..
[1 of 1] Compiling Main             ( app/Main.hs, /home/freezer/workspace/haskell/tarai/dist-newstyle/build/x86_64-linux/ghc-9.4.8/tarai-0.1.0.0/x/tarai/build/tarai/tarai-tmp/Main.o, /home/freezer/workspace/haskell/tarai/dist-newstyle/build/x86_64-linux/ghc-9.4.8/tarai-0.1.0.0/x/tarai/build/tarai/tarai-tmp/Main.dyn_o )
[2 of 2] Linking /home/freezer/workspace/haskell/tarai/dist-newstyle/build/x86_64-linux/ghc-9.4.8/tarai-0.1.0.0/x/tarai/build/tarai/tarai
15
real:5.76[sec]_user:5.74[sec]_sys:0.00[sec]_Memory:3840[KB]
Haxe
Sat Sep 14 06:24:23 PM JST 2024
$ haxelib run formatter -s Tarai.hx

Formatted 1 files in 0.02 s.
-------------------------
Input lines:  13
Output lines: 13
-------------------------
Tarai.hx
class Tarai {
	static function tarai(x:Int, y:Int, z:Int):Int {
		if (x <= y)
			return y;
		else
			return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
	}

	static public function main():Void {
		trace(tarai(15, 5, 0));
	}
}
$ haxe --version
4.3.6
$ java --version
java 22.0.2 2024-07-16
Java(TM) SE Runtime Environment (build 22.0.2+9-70)
Java HotSpot(TM) 64-Bit Server VM (build 22.0.2+9-70, mixed mode, sharing)
$ rm -r Tarai.jar; haxe --main Tarai --jvm Tarai.jar; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] java -jar Tarai.jar
Tarai.hx:10: 15
real:4.66[sec]_user:4.65[sec]_sys:0.01[sec]_Memory:39344[KB]
$ rm -r Tarai.jar; haxe -D analyzer-optimize --main Tarai --jvm Tarai.jar; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] java -jar Tarai.jar
Tarai.hx:10: 15
real:3.57[sec]_user:3.56[sec]_sys:0.01[sec]_Memory:39352[KB]
Hy
Sun Sep 15 02:11:58 AM JST 2024
$ cljfmt -i tarai.hy
tarai.hy
(defn tarai [x y z]
  (if (<= x y)
    y
    (tarai
     (tarai (- x 1) y z)
     (tarai (- y 1) z x)
     (tarai (- z 1) x y))))

(print (tarai 15 5 0))
$ hy --version
hy 0.29.0
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] hy -i < tarai.hy
Hy 0.29.0 using CPython(main) 3.12.6 on Linux
=> ... ... ... ... ... ... => => 15
=> 
now exiting REPL...
real:129.47[sec]_user:129.02[sec]_sys:0.42[sec]_Memory:27204[KB]

I

Idris2
Sun Sep 15 02:34:54 AM JST 2024
$ 
tarai.idr
module Main

tarai : Int -> Int -> Int -> Int
tarai x y z = if x <= y then y else tarai (tarai (x-1) y z) (tarai (y-1) z x) (tarai (z-1) x y)

main : IO ()
main = do
    putStrLn $ show $ tarai 15 5 0
$ idris2 --version
Idris 2, version 0.7.0
$ rm -rf build; idris2 tarai.idr -o a.out; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./build/exec/a.out
15
real:51.49[sec]_user:51.48[sec]_sys:0.01[sec]_Memory:47104[KB]
Inko
Sun Sep  8 06:52:24 PM JST 2024
$ inko fmt tarai.inko
tarai.inko
import std.stdio (STDOUT)

fn tarai(x: Int, y: Int, z: Int) -> Int {
  if x <= y {
    y
  } else {
    tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
  }
}

class async Main {
  fn async main {
    STDOUT.new.print(tarai(15, 5, 0).to_string)
  }
}
$ inko --version
inko 0.16.0
$ rm -rf build; inko build tarai.inko; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] build/tarai
15
real:24.87[sec]_user:24.88[sec]_sys:0.01[sec]_Memory:3584[KB]
$ rm -rf build; inko build --opt balanced tarai.inko; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] build/tarai
15
real:24.85[sec]_user:24.87[sec]_sys:0.00[sec]_Memory:3584[KB]
$ rm -rf build; inko build --opt aggressive tarai.inko; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] build/aggressive/tarai
15
real:11.94[sec]_user:11.97[sec]_sys:0.00[sec]_Memory:3584[KB]
Io
Mon Sep 23 04:52:26 PM JST 2024
$ 
tarai.io
tarai := method(x, y, z,
    if (x <= y,
        y,
        tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    )
)

tarai(15, 5, 0) println
$ io --version
Io Programming Language, v. 20151111
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] io ./tarai.io
15
Command exited with non-zero status 15
real:3949.96[sec]_user:3949.70[sec]_sys:0.00[sec]_Memory:7680[KB]

J

Java
Sat Sep  7 12:09:25 AM JST 2024
$ clang-format-18 -i Tarai.java
Tarai.java
public class Tarai {
  static int tarai(int x, int y, int z) {
    if (x <= y)
      return y;
    else
      return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
  }
  public static void main(String[] args) {
    System.out.println(tarai(15, 5, 0));
  }
}
$ sdk use java 22.0.2-oracle

Using java version 22.0.2-oracle in this shell.
$ java --version
java 22.0.2 2024-07-16
Java(TM) SE Runtime Environment (build 22.0.2+9-70)
Java HotSpot(TM) 64-Bit Server VM (build 22.0.2+9-70, mixed mode, sharing)
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] java Tarai.java
15
real:5.09[sec]_user:5.64[sec]_sys:0.05[sec]_Memory:90648[KB]
$ javac Tarai.java; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] java Tarai
15
real:4.65[sec]_user:4.65[sec]_sys:0.00[sec]_Memory:38764[KB]
Javascript
Sat Sep  7 12:13:58 AM JST 2024
$ npx prettier tarai.js --write
tarai.js 49ms (unchanged)
tarai.js
function tarai(x, y, z) {
  if (x <= y) {
    return y;
  } else {
    return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
  }
}

console.log(tarai(15, 5, 0));
$ node --version
v22.8.0
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] node tarai.js
15
real:10.43[sec]_user:10.42[sec]_sys:0.00[sec]_Memory:49664[KB]
$ deno --version
deno 1.46.3 (stable, release, x86_64-unknown-linux-gnu)
v8 12.9.202.5-rusty
typescript 5.5.2
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] deno run tarai.js
15
real:11.49[sec]_user:11.48[sec]_sys:0.01[sec]_Memory:57660[KB]
$ bun --version
1.1.26
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] bun run tarai.js
15
real:12.43[sec]_user:12.39[sec]_sys:0.03[sec]_Memory:42392[KB]
Julia
Sat Sep  7 12:20:14 AM JST 2024
$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.5 (2024-08-27)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using JuliaFormatter

julia> format("tarai.jl")
true

julia> 
tarai.jl
function tarai(x, y, z)
    if x <= y
        y
    else
        tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    end
end

println(tarai(15, 5, 0))
$ julia --version
julia version 1.10.5
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] julia tarai.jl
15
real:6.78[sec]_user:6.83[sec]_sys:0.27[sec]_Memory:241220[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] julia -O1 tarai.jl
15
real:6.42[sec]_user:6.48[sec]_sys:0.25[sec]_Memory:238644[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] julia -O2 tarai.jl
15
real:6.77[sec]_user:6.84[sec]_sys:0.25[sec]_Memory:241228[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] julia -O3 tarai.jl
15
real:6.77[sec]_user:6.83[sec]_sys:0.26[sec]_Memory:241228[KB]

K

Koka
Sun Sep 15 06:24:30 AM JST 2024
$ 
tarai.kk
fun tarai(x: int, y: int, z: int)
  if x <= y return y 
  tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))

fun main()
  println(tarai(15, 5, 0)) 
$ koka --version
Koka 3.1.2, 00:27:36 May 31 2024 (ghc release version)
version: 3.1.2
bin    : /home/linuxbrew/.linuxbrew/Cellar/koka/3.1.2/bin
lib    : /home/linuxbrew/.linuxbrew/Cellar/koka/3.1.2/lib/koka/v3.1.2
share  : /home/linuxbrew/.linuxbrew/Cellar/koka/3.1.2/share/koka/v3.1.2
output : .koka/v3.1.2/gcc-debug-406b6c
cc     : /usr/bin/gcc
Copyright 2019-2024, Microsoft Research, Daan Leijen, and others.
This program is free software; see the source for copying conditions.
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty
of merchantability or fitness for a particular purpose.
$ koka -c -j4 -O3 -v0 -r -o a.out tarai.kk; chmod +x a.out; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
compile : kklib from: /home/linuxbrew/.linuxbrew/Cellar/koka/3.1.2/share/koka/v3.1.2/kklib
In file included from /home/linuxbrew/.linuxbrew/Cellar/koka/3.1.2/share/koka/v3.1.2/kklib/src/../mimalloc/src/static.c:35,
                 from /home/linuxbrew/.linuxbrew/Cellar/koka/3.1.2/share/koka/v3.1.2/kklib/src/all.c:23:
/home/linuxbrew/.linuxbrew/Cellar/koka/3.1.2/share/koka/v3.1.2/kklib/src/../mimalloc/src/segment.c: In function ‘mi_segment_span_free_coalesce’:
/home/linuxbrew/.linuxbrew/Cellar/koka/3.1.2/share/koka/v3.1.2/kklib/src/../mimalloc/src/segment.c:664:30: warning: ‘__atomic_load_8’ writing 8 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
  664 |   const bool is_abandoned = (segment->thread_id == 0); // mi_segment_is_abandoned(segment);
      |                              ^~~~~~~
cc1: note: destination object is likely at address zero
15
real:7.82[sec]_user:7.82[sec]_sys:0.00[sec]_Memory:2688[KB]
Kotlin
Sat Sep  7 12:25:45 AM JST 2024
$  ktlint --format Tarai.kt
Tarai.kt
fun tarai(
    x: Int,
    y: Int,
    z: Int,
): Int {
    if (x <= y) {
        return y
    } else {
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    }
}

fun main() {
    println(tarai(15, 5, 0))
}
$ sdk use java 22.0.2-oracle

Using java version 22.0.2-oracle in this shell.
$ kotlin -version
Kotlin version 2.0.20-release-360 (JRE 22.0.2+9-70)
$ java --version
java 22.0.2 2024-07-16
Java(TM) SE Runtime Environment (build 22.0.2+9-70)
Java HotSpot(TM) 64-Bit Server VM (build 22.0.2+9-70, mixed mode, sharing)
$ rm -rf Tarai.jar; kotlinc Tarai.kt -include-runtime -d Tarai.jar; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] java -jar Tarai.jar
15
real:4.66[sec]_user:4.67[sec]_sys:0.01[sec]_Memory:40880[KB]

L

LEAN4
Sun Sep 15 08:04:33 AM JST 2024
$ 
Main.lean
import «Tarai»

def main : IO Unit := do
  let stdout ← IO.getStdout
  stdout.putStrLn s!"{tarai 15 5 0}"
Tarai.lean
partial def tarai (x: Int) (y: Int) (z: Int) : Int :=
  if x <= y then
    y
  else
    tarai (tarai (x-1) y z) (tarai (y-1) z x) (tarai (z-1) x y)
$ lean --version
Lean (version 4.11.0, x86_64-unknown-linux-gnu, commit ec3042d94bd1, Release)
$ lake --version
Lake version 5.0.0-ec3042d (Lean version 4.11.0)
$ elan --version
elan 3.1.1 (71ddc6633 2024-02-22)
$ lake clean; lake build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./.lake/build/bin/tarai
Build completed successfully.
15
real:11.32[sec]_user:11.31[sec]_sys:0.00[sec]_Memory:9984[KB]
LiveScript
Sun Sep 15 10:44:45 AM JST 2024
$ 
tarai.ls
tarai = (x, y, z) ->
  if x <= y
    return y
  else
    return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))

console.log tarai(15, 5, 0)
$ lsc --version
LiveScript version 1.6.0
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] lsc tarai.ls
15
real:10.92[sec]_user:10.92[sec]_sys:0.02[sec]_Memory:58924[KB]
Lobster
Sun Sep 15 10:32:26 AM JST 2024
$ 
tarai.lobster
def tarai(x: int, y: int, z: int) -> int:
    if x <= y:
        return y
    else:
        return tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y))

print(tarai(15, 5, 0))
$ rm -rf default.lpak
$ lobster | head
Lobster programming language compiler/runtime (version 2024-05-21T15:49:18-07:00|72fe2da0)
no arguments given - cannot load default.lpak
Usage:
lobster [ OPTIONS ] [ FILE ] [ -- ARGS ]
Compile & run FILE, or omit FILE to load default.lpak
--pak                  Compile to pakfile, don't run.
--cpp                  Compile to C++ code, don't run (see implementation.md!).
--import RELDIR        Additional dir (relative to FILE) to load imports from
--main MAIN            if present, run this main program file after compiling FILE.
--parsedump            Also dump parse tree.
$ lobster --pak tarai.lobster; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] lobster
15
real:112.05[sec]_user:112.05[sec]_sys:0.00[sec]_Memory:9212[KB]
Lua
Mon Sep  9 08:31:43 PM JST 2024
$ stylua tarai.lua
tarai.lua
local function tarai(x, y, z)
	if x <= y then
		return y
	else
		return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
	end
end

print(tarai(15, 5, 0))
$ lua -v
Lua 5.4.7  Copyright (C) 1994-2024 Lua.org, PUC-Rio
$ luajit -v
LuaJIT 2.1.1725453128 -- Copyright (C) 2005-2023 Mike Pall. https://luajit.org/
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] lua tarai.lua
15
real:72.51[sec]_user:72.50[sec]_sys:0.00[sec]_Memory:2688[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] luajit tarai.lua
15
real:11.18[sec]_user:11.18[sec]_sys:0.00[sec]_Memory:2432[KB]

M

Mercury
Sun Sep 15 10:59:25 AM JST 2024
$ 
tarai.m
% tarai.m
:- module tarai.

:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.

:- implementation.
:- import_module int.
:- func tarai(int, int, int) = int.
tarai(X, Y, Z) = R :-
  (
    if X =< Y
    then R = Y
    else R = tarai(tarai(X - 1, Y, Z), tarai(Y - 1, Z, X), tarai(Z - 1, X, Y))
  ).

main(!IO) :-
    io.print(tarai(15, 5, 0), !IO),
    io.nl(!IO).

:- end_module tarai.
$ mmc --version
Mercury Compiler, version 22.01.8, on x86_64-pc-linux-gnu
Copyright (C) 1993-2012 The University of Melbourne
Copyright (C) 2013-2023 The Mercury team
$ rm -rf a.out; mmc -o a.out tarai.m; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:3.46[sec]_user:3.45[sec]_sys:0.01[sec]_Memory:40704[KB]
$ rm -rf a.out; mmc -O6 -o a.out tarai.m; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:4.79[sec]_user:4.78[sec]_sys:0.01[sec]_Memory:40576[KB]
Mojo
Sat Sep  7 12:29:40 AM JST 2024
$ mojo format tarai.🔥
All done! ✨ 🍰 ✨
1 file left unchanged.
tarai.🔥
fn tarai(x: Int, y: Int, z: Int) -> Int:
    if x <= y:
        return y
    else:
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))


def main():
    print(tarai(15, 5, 0))
$ mojo --version
mojo 24.4.0 (2cb57382)
$ rm -rf tarai; mojo build tarai.🔥; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:5.38[sec]_user:5.37[sec]_sys:0.00[sec]_Memory:8320[KB]

N

Nelua
Sun Sep 15 11:08:48 JST 2024
$ 
tarai.nelua
do
  local function tarai(x: integer, y: integer, z: integer): integer
    if x <= y then
      return y
    end
    return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
  end
  print(tarai(15, 5, 0))
end
$ nelua --version
Nelua 0.2.0-dev
Build number: 0
Git date: 2024-08-04
Git hash: 38c2d9ca14c992ddcd73f4067af8c6f37c550979
Semantic version: 0.2.0-dev.0+38c2d9ca
Copyright (C) 2019-2024 Eduardo Bart (https://nelua.io/)
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] nelua tarai.nelua
15
real:4.42[sec]_user:4.40[sec]_sys:0.02[sec]_Memory:30592[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] nelua --release tarai.nelua
15
real:4.42[sec]_user:4.39[sec]_sys:0.02[sec]_Memory:30208[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] nelua --maximum-performance tarai.nelua
15
real:2.46[sec]_user:2.41[sec]_sys:0.04[sec]_Memory:31400[KB]
Nim
Tue Sep 10 08:03:04 PM JST 2024
$ nimpretty tarai.nim
tarai.nim
proc tarai(x: int, y: int, z: int): int =
    if x <= y:
        return y
    else:
        return tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y))

echo tarai(15, 5, 0)
$ nim --version
Nim Compiler Version 2.0.8 [Linux: amd64]
Compiled at 2024-07-03
Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release -d:nimUseLinenoise
$ rm -rf a.out; nim c -d:release --opt:size --hints:off -o:a.out tarai.nim; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:5.38[sec]_user:5.38[sec]_sys:0.00[sec]_Memory:1280[KB]
$ rm -rf a.out; nim cpp -d:release --opt:size --hints:off -o:a.out tarai.nim; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:5.59[sec]_user:5.59[sec]_sys:0.00[sec]_Memory:3584[KB]
$ rm -rf a.out; nim c -d:release --opt:speed --hints:off -o:a.out tarai.nim; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:5.02[sec]_user:5.02[sec]_sys:0.00[sec]_Memory:1408[KB]
$ rm -rf a.out; nim cpp -d:release --opt:speed --hints:off -o:a.out tarai.nim; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:2.35[sec]_user:2.35[sec]_sys:0.00[sec]_Memory:3712[KB]
Nit
Sun Sep 15 01:54:42 PM JST 2024
$ 
tarai.nit
fun tarai(x: Int, y: Int, z: Int): Int
do
    if x <= y then
        return y
    else 
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    end
end

print tarai(15, 5, 0)
$ nit --version
v0.8-3758-g17eaca044
$ rm a.out; nitc -o a.out tarai.nit; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
rm: cannot remove 'a.out': No such file or directory
tarai.mk:29: "[_] stack-traces disabled. Please install libunwind-dev."
15
real:6.19[sec]_user:6.19[sec]_sys:0.00[sec]_Memory:2944[KB]
$ rm a.out; nitc --release -o a.out tarai.nit; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
tarai.mk:29: "[_] stack-traces disabled. Please install libunwind-dev."
15
real:6.15[sec]_user:6.15[sec]_sys:0.00[sec]_Memory:2816[KB]
$ rm a.out; nitc --no-check-all -o a.out tarai.nit; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
tarai.mk:29: "[_] stack-traces disabled. Please install libunwind-dev."
15
real:6.15[sec]_user:6.15[sec]_sys:0.00[sec]_Memory:2816[KB]

O

OCaml
Sat Sep  7 12:38:16 AM JST 2024
$ dune fmt
bin/main.ml
let rec tarai x y z =
  if x <= y then y
  else tarai (tarai (x - 1) y z) (tarai (y - 1) z x) (tarai (z - 1) x y)

let () = Printf.printf "%d\n" (tarai 15 5 0)
$ dune --version
3.16.0
$ ocaml --version
The OCaml toplevel, version 5.2.0
$ dune build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] dune exec tarai
15                                 
real:4.82[sec]_user:4.80[sec]_sys:0.01[sec]_Memory:25472[KB]
$ dune build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./_build/default/bin/main.exe
15
real:4.79[sec]_user:4.78[sec]_sys:0.00[sec]_Memory:2688[KB]
Odin
Sun Sep 15 02:18:58 PM JST 2024
$ 
tarai.odin
package main

import "core:fmt"

tarai :: proc(x: i64, y: i64, z: i64) -> i64 {
    if x <= y {
        return y
    } else {
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    }
}

main :: proc() {
    fmt.println(tarai(15, 5, 0))
}
$ odin version
odin version dev-2024-09:16c5c69a4
$ rm -rf tarai; odin build tarai.odin -file; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:6.27[sec]_user:6.27[sec]_sys:0.00[sec]_Memory:1792[KB]
$ rm -rf tarai; odin build tarai.odin -o:speed -file; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:3.98[sec]_user:3.98[sec]_sys:0.00[sec]_Memory:1664[KB]
$ rm -rf tarai; odin build tarai.odin -o:speed -no-bounds-check -file; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:5.37[sec]_user:5.37[sec]_sys:0.00[sec]_Memory:1664[KB]
$ rm -rf tarai; odin build tarai.odin -o:speed -thread-count:4 -file; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:3.98[sec]_user:3.98[sec]_sys:0.00[sec]_Memory:1664[KB]
$ rm -rf tarai; odin build tarai.odin -o:speed -no-bounds-check -thread-count:4 -file; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:5.37[sec]_user:5.37[sec]_sys:0.00[sec]_Memory:1664[KB]
Onyx
Sun Sep 15 03:11:38 PM JST 2024
$ 
tarai.onyx
use core {*}

tarai :: (x: i64, y: i64, z: i64) -> i64 {
    if (x <= y) {
        return y
    } else {
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    }
}

main :: () {
    println(tarai(15, 5, 0))
}
$ onyx version
Onyx toolchain version v0.1.12
Runtime: wasmer
Built:   Mon May 20 01:50:41 2024
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] onyx run tarai.onyx
15
real:6.92[sec]_user:6.92[sec]_sys:0.03[sec]_Memory:78196[KB]
$ rm -rf out.wasm; onyx build tarai.onyx; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] onyx run out.wasm
15
real:6.86[sec]_user:6.89[sec]_sys:0.01[sec]_Memory:51804[KB]

P

Pascal
Sat Sep  7 12:40:36 AM JST 2024
$ ptop tarai.pas tarai.pas
tarai.pas

Program tarai(output);

Uses sysutils;

Function tarai(x, y, z: integer) : integer;
Begin
  If x <= y Then
    tarai := y
  Else
    tarai := tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y))
End;

Begin
  writeln(tarai(15, 5, 0));
End.
$ fpc -version | head
[0.004] Free Pascal Compiler version 3.2.2+dfsg-32 [2024/01/05] for x86_64
[0.004] Copyright (c) 1993-2021 by Florian Klaempfl and others
[0.004] error: No source file name in command line
[0.004] error: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode
$ rm -rf tarai; fpc tarai.pas; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
Free Pascal Compiler version 3.2.2+dfsg-32 [2024/01/05] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling tarai.pas
Linking tarai
16 lines compiled, 0.1 sec
15
real:8.26[sec]_user:8.26[sec]_sys:0.00[sec]_Memory:384[KB]
$ rm -rf tarai; fpc -O4 tarai.pas; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
Free Pascal Compiler version 3.2.2+dfsg-32 [2024/01/05] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling tarai.pas
Linking tarai
16 lines compiled, 0.1 sec
15
real:5.90[sec]_user:5.90[sec]_sys:0.00[sec]_Memory:384[KB]
Peregrine
Sun Sep 15 03:26:43 PM JST 2024
$ 
tarai.pe
def tarai(x: int, y: int, z: int) -> int :
    if x <= y:
        return y
    else:
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))

def main() :
    printf("%d\n", tarai(15, 5, 0))
$ peregrine.elf | head
Peregrine Compiler (C) The Peregrine Organisation, MPL-2.0
Usage: peregrine [command] [options] [file] -o [output file]

Peregrine Commands:
	compile          - compiles a given file
	help             - prints out help

Peregrine Options:
	-release         - create release builds
	-debug           - create debug builds
$ rm -rf a.out; peregrine.elf compile tarai.pe -o a.out; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:7.00[sec]_user:7.00[sec]_sys:0.00[sec]_Memory:3712[KB]
$ rm -rf a.out; peregrine.elf compile tarai.pe -static -o a.out; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:7.00[sec]_user:7.00[sec]_sys:0.00[sec]_Memory:640[KB]
$ rm -rf a.out; peregrine.elf compile tarai.pe -release -o a.out; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:3.98[sec]_user:3.98[sec]_sys:0.00[sec]_Memory:3712[KB]
$ rm -rf a.out; peregrine.elf compile tarai.pe -release -static -o a.out; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:3.98[sec]_user:3.98[sec]_sys:0.00[sec]_Memory:640[KB]
Perl
Sun Sep 15 04:13:22 PM JST 2024
$ perltidy -pbp tarai.pl | sponge tarai.pl
tarai.pl
sub tarai {
    local ( $x, $y, $z ) = @_;
    return $y if $x <= $y;
    tarai(
        tarai( $x - 1, $y, $z ),
        tarai( $y - 1, $z, $x ),
        tarai( $z - 1, $x, $y )
    );
}
print tarai( 15, 5, 0 ), "\n";
$ perl --version

This is perl 5, version 40, subversion 0 (v5.40.0) built for x86_64-linux

Copyright 1987-2024, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at https://www.perl.org/, the Perl Home Page.

$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] perl tarai.pl
15
real:601.45[sec]_user:601.43[sec]_sys:0.01[sec]_Memory:5120[KB]
Php
Fri Sep 13 08:22:43 PM JST 2024
$ php-cs-fixer fix tarai.php
PHP CS Fixer 3.64.0 (209f776) Space Sets by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.3.11
Running analysis on 1 core sequentially.
You can enable parallel runner and speed up the analysis! Please see usage docs for more information.
Loaded config default.
Using cache file ".php-cs-fixer.cache".
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

tarai.php
<?php

function tarai($x, $y, $z)
{
    if ($x <= $y) {
        return $y;
    } else {
        return tarai(
            tarai($x - 1, $y, $z),
            tarai($y - 1, $z, $x),
            tarai($z - 1, $x, $y)
        );
    }
}

echo tarai(15, 5, 0), "\n";
$ php --version
PHP 8.3.11 (cli) (built: Aug 27 2024 19:16:34) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.11, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.11, Copyright (c), by Zend Technologies
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] php tarai.php
15
real:58.44[sec]_user:58.43[sec]_sys:0.01[sec]_Memory:31324[KB]
Pike
Sun Sep 15 04:53:59 PM JST 2024
$ clang-format-18 --style="{ BasedOnStyle: Google }" -i tarai.pike
tarai.pike
int tarai(int x, int y, int z) {
  if (x <= y) {
    return y;
  } else {
    return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
  }
}

int main() {
  write("%d\n", tarai(15, 5, 0));
  return 0;
}
$ pike --version
Pike v8.0 release 1738 Copyright © 1994-2022 Linköping University
Pike comes with ABSOLUTELY NO WARRANTY; This is free software and you are
welcome to redistribute it under certain conditions; read the files
COPYING and COPYRIGHT in the Pike distribution for more details.
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] pike tarai.pike
15
real:152.94[sec]_user:152.93[sec]_sys:0.00[sec]_Memory:6784[KB]
Pinecone
Sun Sep 15 05:40:13 PM JST 2024
$ 
tarai.pn
print: tarai: 15, 5, 0

tarai :: {x: Int, y: Int, z: Int} -> {Int}: (
    in.x <= in.y ?
        out: in.y
    | 
        out: tarai: (tarai: in.x - 1, in.y, in.z), (tarai: in.y - 1, in.z, in.x), (tarai: in.z - 1, in.x, in.y)

    out
)
$ pinecone -v
Pinecone version 0.5.1
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] pinecone tarai.pn
15
real:1867.72[sec]_user:1867.69[sec]_sys:0.00[sec]_Memory:4736[KB]
Poly/ML
Sun Sep 15 05:10:27 PM JST 2024
$ 
tarai.ml
fun tarai(x, y, z) =
  if x <= y then y
  else tarai(tarai((x - 1), y, z), tarai((y - 1), z, x), tarai((z - 1), x, y));

fun main() = print(Int.toString(tarai(15, 5, 0)) ^ "\n");
$ poly -v
Poly/ML 5.9.1 Release    RTS version: X86_64-5.9.1
$ rm -rf a.out; polyc tarai.ml; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:6.68[sec]_user:6.68[sec]_sys:0.00[sec]_Memory:4992[KB]
Pony
Sun Sep 15 06:46:49 PM JST 2024
$ 
main.pony
actor Main
  fun tarai(x: I32, y: I32, z: I32): I32 =>
    if x <= y then
      return y
    else
      return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    end

  new create(env: Env) =>
    env.out.print(tarai(15, 5, 0).string())
$ ponyc --version
0.58.5-0d607b5 [release]
Compiled with: LLVM 15.0.7 -- Clang-18.1.3-x86_64
Defaults: pic=true
$ rm -rf a.out; ponyc -b a.out; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
Building builtin -> /home/freezer/.local/share/ponyup/ponyc-release-0.58.5-x86_64-linux-ubuntu24.04/packages/builtin
Building . -> /home/freezer/workspace/pony/tarai
Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
 Descriptors
Verifying
Writing ./a.out.o
Linking ./a.out
15
real:5.78[sec]_user:6.12[sec]_sys:0.00[sec]_Memory:2688[KB]
Python
Sat Sep  7 12:45:48 AM JST 2024
$ black tarai.py
All done! ✨ 🍰 ✨
1 file left unchanged.
tarai.py
def tarai(x: int, y: int, z: int) -> int:
    if x <= y:
        return y
    else:
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))


print(tarai(15, 5, 0))
$ python3 --version
Python 3.12.5
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] python3 tarai.py
15
real:131.03[sec]_user:131.00[sec]_sys:0.02[sec]_Memory:10240[KB]

R

R
Mon Sep 16 03:27:31 AM JST 2024
$ R

R version 4.4.1 (2024-06-14) -- "Race for Your Life"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> styler::style_file("tarai.R")
Styling  1  files:
 tarai.R ✔ 
────────────────────────────────────────
Status	Count	Legend 
✔ 	1	File unchanged.
ℹ 	0	File changed.
✖ 	0	Styling threw an error.
────────────────────────────────────────
> 

Save workspace image? [y/n/c]: n

tarai.R
tarai <- function(x, y, z) {
  force(x)
  force(y)
  force(z)
  if (x <= y) {
    return(y)
  } else {
    return(tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y)))
  }
}
print(tarai(15, 5, 0))
$ R --version
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] Rscript tarai.R
[1] 15
real:3365.85[sec]_user:3365.62[sec]_sys:0.09[sec]_Memory:71520[KB]
Racket
Fri Sep 13 08:28:53 PM JST 2024
$ raco fmt -i tarai.rkt
tarai.rkt
#lang racket
(define (tarai x y z)
  (if (<= x y) y (tarai (tarai (- x 1) y z) (tarai (- y 1) z x) (tarai (- z 1) x y))))

(printf "~a\n" (tarai 15 5 0))
$ racket --version
Welcome to Racket v8.14 [cs].
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] racket tarai.rkt
15
real:7.27[sec]_user:6.98[sec]_sys:0.26[sec]_Memory:100916[KB]
$ rm -rf tarai; raco exe tarai.rkt; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:6.58[sec]_user:6.52[sec]_sys:0.06[sec]_Memory:134144[KB]
$ rm -rf compiled/tarai_rkt.zo; raco make tarai.rkt; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] racket compiled/tarai_rkt.zo
15
real:6.73[sec]_user:6.61[sec]_sys:0.10[sec]_Memory:100892[KB]
Raku
Mon Sep 16 08:01:15 AM JST 2024
$ 
tarai.p6
sub tarai ( $x, $y, $z ) {
    if $x <= $y {
        return $y;
    } else {
        return tarai(tarai( $x - 1, $y, $z ), tarai( $y - 1, $z, $x ), tarai( $z - 1, $x, $y ));
    }
}
print tarai( 15, 5, 0 ), "\n";
$ raku --version
Welcome to Rakudo™ v2024.08.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2024.08.
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] raku tarai.p6
15
real:518.38[sec]_user:518.37[sec]_sys:0.03[sec]_Memory:137884[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] raku --optimize=1 tarai.p6
15
real:1374.61[sec]_user:1370.54[sec]_sys:4.06[sec]_Memory:188836[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] raku --optimize=2 tarai.p6
15
real:515.44[sec]_user:515.43[sec]_sys:0.04[sec]_Memory:137392[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] raku --optimize=3 tarai.p6
15
real:513.60[sec]_user:513.56[sec]_sys:0.04[sec]_Memory:137624[KB]
Reason
Mon Sep 16 07:19:34 AM JST 2024
$ refmt --in-place bin/main.re
bin/main.re
let rec tarai = (x: int, y: int, z: int) =>
  if (x <= y) {
    y;
  } else {
    tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
  };

let () = {
  Printf.printf("%d\n", tarai(15, 5, 0));
};
$ dune --version
3.16.0
$ refmt --version
Reason 3.12.0 @ 
$ dune build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] dune exec tarai
15                                  
real:4.82[sec]_user:4.80[sec]_sys:0.01[sec]_Memory:24960[KB]
$ dune build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./_build/default/bin/main.exe
15                                 
real:4.79[sec]_user:4.79[sec]_sys:0.00[sec]_Memory:3200[KB]
ReScript
Tue Oct  8 06:26:59 PM JST 2024
$ 
src/tarai.res
let rec tarai = (x, y, z) => if x <= y {
    y
  } else {
    tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
  }
  
Console.log(tarai(15, 5, 0))
$ npx rescript -v
11.1.4
$ npx rescript
>>>> Start compiling
Dependency on @rescript/core
Dependency Finished
>>>> Finish compiling 10 mseconds
$ node --version
v22.9.0
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] node src/tarai.res.mjs
15
real:9.13[sec]_user:9.12[sec]_sys:0.01[sec]_Memory:48768[KB]
$ deno --version
deno 1.46.3 (stable, release, x86_64-unknown-linux-gnu)
v8 12.9.202.5-rusty
typescript 5.5.2
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] deno run src/tarai.res.mjs
15
real:9.60[sec]_user:9.58[sec]_sys:0.01[sec]_Memory:58196[KB]
$ bun --version
1.1.29
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] bun run src/tarai.res.mjs
15
real:13.08[sec]_user:13.03[sec]_sys:0.02[sec]_Memory:43224[KB]
Ring
Mon Sep 16 04:41:11 PM JST 2024
$ 
tarai.ring
print("#{tarai(15, 5, 0)}\n")

func tarai(x, y, z) {
  if x <= y
    return y
  else
    return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
  ok
}
$ ring | head
===========================================================================
Ring version 1.22.0 
2013-2024, Mahmoud Fayed <msfclipper@yahoo.com>
Usage : ring filename.ring [Options]
===========================================================================
-tokens   :  Print a list of tokens in the source code file
-rules    :  Print grammar rules applied on the tokens
-ic       :  Print the intermediate byte code (before execution)
-icfinal  :  Print the final byte code (after execution)
-cgi      :  Print http response header before error messages
$ rm -rf tarai; ring2exe tarai.ring -static; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
Ring2EXE: Process File : tarai.ring
Ring2EXE: Start building the application...
Ring2EXE: Generate C source code file...
Ring2EXE: Generation Time : 0.00 seconds...
Ring2EXE: Generate batch|script file...
Ring2EXE: Generate batch|script file for static building...
Ring2EXE: Build the Executable File...
Ring2EXE: End of building script...
Ring2EXE: Executable file is ready!
Ring2EXE: End of building process...
Ring2EXE: Clear Temp. Files...
15
real:2037.11[sec]_user:2037.08[sec]_sys:0.00[sec]_Memory:14080[KB]
Ruby
Sat Sep  7 12:52:07 AM JST 2024
$ rubyfmt -i tarai.rb
tarai.rb
def tarai(x, y, z)
  if x <= y
    return y
  else
    return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
  end
end

puts(tarai(15, 5, 0))
$ ruby --version
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ruby tarai.rb
15
real:81.58[sec]_user:81.57[sec]_sys:0.01[sec]_Memory:20608[KB]
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ruby --yjit tarai.rb
15
real:15.12[sec]_user:15.11[sec]_sys:0.00[sec]_Memory:20736[KB]
Rune
Mon Sep 16 03:39:15 PM JST 2024
$ rune fmt tarai.rn
tarai.rn
fn tarai(x, y, z) {
    if x <= y {
        y
    } else {
        tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    }
}

pub fn main() {
    dbg(tarai(15, 5, 0));
}
$ rune help | head
The Rune Language Interpreter git-

Usage: rune [OPTIONS] [COMMAND]

Commands:
  check            Run checks but do not execute
  doc              Build documentation
  test             Run all tests but do not execute
  bench            Run the given program as a benchmark
  run              Run the designated script
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] rune run tarai.rn
15
real:642.86[sec]_user:642.83[sec]_sys:0.01[sec]_Memory:13288[KB]
Rust
Thu Nov 21 05:29:38 PM JST 2024
$ cargo fmt
src/main.rs
fn tarai(x: isize, y: isize, z: isize) -> isize {
    if x <= y {
        y
    } else {
        tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
    }
}

fn main() {
    println!("{}", tarai(15, 5, 0));
}
$ rustc --version
rustc 1.82.0 (f6e511eec 2024-10-15)
$ cargo clean; cargo build --release; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./target/release/tarai
     Removed 11 files, 787.8KiB total
   Compiling tarai v0.1.0 (/home/kato/workspace/rust/tarai)
    Finished `release` profile [optimized] target(s) in 0.15s
15
real:4.00[sec]_user:4.00[sec]_sys:0.00[sec]_Memory:1920[KB]

S

Scala
Sat Sep  7 12:58:50 AM JST 2024
$ sbt scalafmtAll
[info] welcome to sbt 1.10.1 (Oracle Corporation Java 22.0.2)
[info] loading settings for project tarai-build from plugins.sbt ...
[info] loading project definition from /home/freezer/workspace/scala/tarai/project
[info] loading settings for project tarai from build.sbt ...
[info] set current project to tarai (in build file:/home/freezer/workspace/scala/tarai/)
[info] scalafmt: Formatting 1 Scala sources (/home/freezer/workspace/scala/tarai)...
[success] Total time: 2 s, completed Sep 6, 2024, 3:58:56 PM
./src/main/scala/Tarai.scala
object Tarai {
  def tarai(x: Int, y: Int, z: Int): Int = {
    if (x <= y) y
    else tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
  }

  def main(args: Array[String]): Unit = {
    println(tarai(15, 5, 0))
  }
}
$ sdk use java 22.0.2-oracle

Using java version 22.0.2-oracle in this shell.
$ scala --version
Scala code runner version: 1.4.0
Scala version (default): 3.5.0
$ sbt --version
sbt script version: 1.10.1
$ java --version
java 22.0.2 2024-07-16
Java(TM) SE Runtime Environment (build 22.0.2+9-70)
Java HotSpot(TM) 64-Bit Server VM (build 22.0.2+9-70, mixed mode, sharing)
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] scala ./src/main/scala/Tarai.scala
15
real:4.38[sec]_user:4.20[sec]_sys:0.09[sec]_Memory:103552[KB]
$ sbt clean; sbt assembly; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] java -jar ./target/scala-3.5.0/tarai-assembly-0.1.0-SNAPSHOT.jar
[info] welcome to sbt 1.10.1 (Oracle Corporation Java 22.0.2)
[info] loading settings for project tarai-build from plugins.sbt ...
[info] loading project definition from /home/freezer/workspace/scala/tarai/project
[info] loading settings for project tarai from build.sbt ...
[info] set current project to tarai (in build file:/home/freezer/workspace/scala/tarai/)
[success] Total time: 0 s, completed Sep 6, 2024, 3:59:12 PM
[info] welcome to sbt 1.10.1 (Oracle Corporation Java 22.0.2)
[info] loading settings for project tarai-build from plugins.sbt ...
[info] loading project definition from /home/freezer/workspace/scala/tarai/project
[info] loading settings for project tarai from build.sbt ...
[info] set current project to tarai (in build file:/home/freezer/workspace/scala/tarai/)
[info] compiling 1 Scala source to /home/freezer/workspace/scala/tarai/target/scala-3.5.0/classes ...
[info] 2 file(s) merged using strategy 'Rename' (Run the task at debug level to see the details)
[info] 2 file(s) merged using strategy 'Discard' (Run the task at debug level to see the details)
[info] Built: /home/freezer/workspace/scala/tarai/target/scala-3.5.0/tarai-assembly-0.1.0-SNAPSHOT.jar
[info] Jar hash: 0928fc508db635aa2b34e3959e75d8f18e5c99cd
[success] Total time: 5 s, completed Sep 6, 2024, 3:59:22 PM
15
real:4.02[sec]_user:4.08[sec]_sys:0.02[sec]_Memory:52920[KB]
Seed7
Sun Sep 22 05:35:35 PM JST 2024
$ 
tarai.sd7
$ include "seed7_05.s7i";

const func integer: tarai(in integer: x, in integer: y, in integer: z) is func
  result
    var integer: r is y;
  begin
    if x <= y then
      r := y;
    else
      r := tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y));
    end if;
  end func;

const proc: main is func
  begin
    writeln(tarai(15, 5, 0));
  end func;
$ s7c -? | head
SEED7 COMPILER Version 3.2.70 Copyright (c) 1990-2024 Thomas Mertes
usage: s7c [options] source

Options:
  -?   Write Seed7 compiler usage.
  -On  Tell the C compiler to optimize with level n (n is between 1 and 3).
  -O   Equivalent to -O1
  -S   Specify the stack size of the executable (e.g.: -S 16777216).
  -b   Specify the directory of the Seed7 runtime libraries (e.g.: -b ../bin).
  -c   Specify configuration (C compiler, etc.) to be used (e.g.: -c emcc).
$ rm -rf tarai; s7c tarai.sd7; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
SEED7 COMPILER Version 3.2.70 Copyright (c) 1990-2024 Thomas Mertes
Source: tarai.sd7
Compiling the program ...
Generating code ...
after walk_const_list
667 declarations processed
148 optimizations done
98 evaluations done
1 division checks inserted
34 range checks inserted
89 index checks inserted
95 overflow checks inserted
Calling the C compiler ...
gcc -w -ffunction-sections -fdata-sections -c tmp_tarai.c 2>tmp_tarai.cerrs >/dev/null
Calling the linker ...
gcc -Wl\,--strip-debug -Wl\,--gc-sections -o tarai tmp_tarai.o /home/freezer/seed7/bin/s7_data.a /home/freezer/seed7/bin/seed7_05.a 2>tmp_tarai.lerrs >/dev/null
15
real:8.69[sec]_user:8.69[sec]_sys:0.00[sec]_Memory:1536[KB]
$ rm -rf tarai; s7c -O3 tarai.sd7; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
SEED7 COMPILER Version 3.2.70 Copyright (c) 1990-2024 Thomas Mertes
Source: tarai.sd7
Compiling the program ...
Generating code ...
after walk_const_list
667 declarations processed
148 optimizations done
98 evaluations done
1 division checks inserted
34 range checks inserted
89 index checks inserted
95 overflow checks inserted
Calling the C compiler ...
gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_tarai.c 2>tmp_tarai.cerrs >/dev/null
Calling the linker ...
gcc -Wl\,--strip-debug -Wl\,--gc-sections -o tarai tmp_tarai.o /home/freezer/seed7/bin/s7_data.a /home/freezer/seed7/bin/seed7_05.a 2>tmp_tarai.lerrs >/dev/null
15
real:2.96[sec]_user:2.96[sec]_sys:0.00[sec]_Memory:1536[KB]
$ rm -rf tarai; s7c -O3 -oc3 tarai.sd7; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
SEED7 COMPILER Version 3.2.70 Copyright (c) 1990-2024 Thomas Mertes
Source: tarai.sd7
Compiling the program ...
Generating code ...
after walk_const_list
667 declarations processed
259 optimizations done
47 functions inlined
290 evaluations done
1 division checks inserted
30 range checks inserted
3 range checks optimized away
99 index checks inserted
2 index checks optimized away
83 overflow checks inserted
8 overflow checks optimized away
Calling the C compiler ...
gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_tarai.c 2>tmp_tarai.cerrs >/dev/null
Calling the linker ...
gcc -Wl\,--strip-debug -Wl\,--gc-sections -o tarai tmp_tarai.o /home/freezer/seed7/bin/s7_data.a /home/freezer/seed7/bin/seed7_05.a 2>tmp_tarai.lerrs >/dev/null
15
real:3.38[sec]_user:3.38[sec]_sys:0.00[sec]_Memory:1408[KB]
Squirrel
Wed Sep 18 08:44:52 PM JST 2024
$ 
tarai.nut
function tarai(x, y, z)
{
    if (x <= y)
        return y;
    else
        return tarai( tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y) );
}

print( tarai(15, 5, 0) );
print( "\n" );
$ sq -v
Squirrel 3.2 stable Copyright (C) 2003-2022 Alberto Demichelis (64 bits)
$ rm -rf out.cnut;sq -c tarai.nut; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] sq out.cnut
15
real:198.88[sec]_user:198.91[sec]_sys:0.00[sec]_Memory:3968[KB]
SWI-Prolog
Tue Sep 17 09:14:45 PM JST 2024
$ 
tarai.swi
tarai(X, Y, _, Y) :-
    X =< Y, !.
tarai(X, Y, Z, R) :-
    X1 is X-1,
    Y1 is Y-1,
    Z1 is Z-1,
    tarai(X1, Y, Z, R1),
    tarai(Y1, Z, X, R2),
    tarai(Z1, X, Y, R3),
    tarai(R1, R2, R3, R).
     
main :-
    tarai(15, 5, 0, _),
    !.
$ swipl --version
SWI-Prolog version 9.2.7 for x86_64-linux
$ rm -rf a.out; swipl -O -g main -o a.out -c tarai.swi; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
% Disabled autoloading (loaded 37 files)
% Disabled autoloading (loaded 0 files)
real:240.84[sec]_user:240.61[sec]_sys:0.20[sec]_Memory:9984[KB]
Swift
Thu Nov 21 06:01:09 PM JST 2024
$ swift-format -i Sources/main.swift
swift-format: symbol lookup error: swift-format: undefined symbol: $s10Foundation3URLVMn
Sources/main.swift
func tarai(x: Int, y: Int, z: Int) -> Int {
  if x <= y {
    return y
  } else {
    return tarai(
      x: tarai(x: x - 1, y: y, z: z), y: tarai(x: y - 1, y: z, z: x), z: tarai(x: z - 1, y: x, z: y)
    )
  }
}

print(tarai(x: 15, y: 5, z: 0))
$ swift --version
Swift version 6.0.2 (swift-6.0.2-RELEASE)
Target: x86_64-unknown-linux-gnu
$ swift package clean; swift build; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./.build/debug/tarai
Building for debugging...
[8/8] Linking tarai
Build complete! (2.39s)
15
real:34.15[sec]_user:34.15[sec]_sys:0.00[sec]_Memory:9216[KB]
$ swift package clean; swift build -c release; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./.build/release/tarai
Building for production...
[5/5] Linking tarai
Build complete! (0.53s)
15
real:4.71[sec]_user:4.70[sec]_sys:0.00[sec]_Memory:8832[KB]

V

V
Sat Sep  7 01:12:47 AM JST 2024
$ v fmt -w tarai.v
Already formatted file: /home/freezer/workspace/v/tarai/tarai.v
tarai.v
fn tarai(x int, y int, z int) int {
	if x <= y {
		return y
	} else {
		return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y))
	}
}

fn main() {
	println(tarai(15, 5, 0))
}
$ v --version
V 0.4.7 9238dd6
$ \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] v run tarai.v
15
real:7.47[sec]_user:7.46[sec]_sys:0.02[sec]_Memory:48232[KB]
$ rm -rf a.out; v -prod -cc gcc-14 -skip-unused -manualfree -prealloc -gc none -no-bounds-checking -o a.out tarai.v; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:2.57[sec]_user:2.57[sec]_sys:0.00[sec]_Memory:1280[KB]
$ rm -rf a.out; v -prod -cc clang-18 -skip-unused -manualfree -prealloc -gc none -no-bounds-checking -o a.out tarai.v; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:4.27[sec]_user:4.27[sec]_sys:0.00[sec]_Memory:1280[KB]
Vala
Mon Sep 16 04:28:52 PM JST 2024
$ 
tarai.vala
int tarai (int x, int y, int z) {
    if (x <= y) return y;
    else return tarai (tarai (x - 1, y, z), tarai (y - 1, z, x), tarai (z - 1, x, y));
}

void main () {
    print ("%d\n", tarai (15, 5, 0));
}
$ valac --version
Vala 0.56.17
$ rm -rf a.out; valac -o a.out tarai.vala; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./a.out
15
real:6.79[sec]_user:6.79[sec]_sys:0.00[sec]_Memory:3328[KB]

Z

Zig
Sat Sep  7 01:15:09 AM JST 2024
$ zig fmt tarai.zig
tarai.zig
const std = @import("std");

fn tarai(x: i32, y: i32, z: i32) i32 {
    if (x <= y) {
        return y;
    } else {
        return tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y));
    }
}

pub fn main() !void {
    const stdout = std.io.getStdOut().writer();
    try stdout.print("{d}\n", .{
        tarai(15, 5, 0),
    });
}
$ zig version
0.14.0-dev.1472+3929cac15
$ rm -rf tarai; zig build-exe tarai.zig; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:5.96[sec]_user:5.96[sec]_sys:0.00[sec]_Memory:384[KB]
$ rm -rf tarai; zig build-exe -OReleaseFast tarai.zig; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:3.82[sec]_user:3.82[sec]_sys:0.00[sec]_Memory:256[KB]
$ rm -rf tarai; zig build-exe -OReleaseSafe tarai.zig; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:4.04[sec]_user:4.04[sec]_sys:0.00[sec]_Memory:256[KB]
$ rm -rf tarai; zig build-exe -OReleaseSmall tarai.zig; \time -o /dev/stdout -f real:%e[sec]_user:%U[sec]_sys:%S[sec]_Memory:%M[KB] ./tarai
15
real:5.38[sec]_user:5.38[sec]_sys:0.00[sec]_Memory:256[KB]
6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?