swapview is a simple program to view processes' swap usage on Linux. This repository is the one of multiple implementations, intended to be a lilydjwg's version of Hello World program. For a daily use version, see swapview.
Install all the dependencies for your interested versions, then run make -k
. It will build all that can be built.
To test and see the speed comparison, either use bench.py
or run_benchmark
. bench.py
uses Python 3.4+ and depends on python-toml
.
run_benchmark
is a Rust version. Install latest Rust and Cargo, then change your working directory to benchmark
and run cargo build --release
. If the build fails, it's because your Rust is too old or too new....
Run ./run_benchmark <benchmark.toml
and wait for it to finish. Failed ones (e.g. because you don't have the dependencies installed) will be marked as failed so you don't need to edit benchmark.toml
to disable the ones you can't run.
You can give ./run_benchmark
names to selectively run some versions, e.g.
./run_benchmark C C++14 'Rust*' <benchmark.toml
Of course you should have corresponding compilers / interpreters installed.
You can (edit and then) run make
to build all that needs to be built.
- Bash, requires
bc
- Bash_parallel, Bash version using GNU parallel
- C
- C++98
- C++98_omp, openmp paralleled version
- C++14
- C++14_boost, C++ version using the boost library
- C++17
- CSharp (mono)
- ChezScheme
- Chicken, format (will be installed by
make
) - CommonLisp_opt, sbcl
- CommonLisp_old, sbcl, maynbe others also work
- CoffeeScript, requires promise (will be installed by
make
) - CoffeeScript_parallel, a parallel version, requires promise (will be installed by
make
) - Crystal, with fiber and multi-process versions, tested with 0.28.0
- Cython
- D,
dmd
orldmd
(LLVM version) - Dart
- Elixir
- Erlang
- Go >=1.8
- Guile >= 2.1
- Haskell, requires
haskell-strict
- Java, >= Java 8
- Lua, requires lua-filesystem, works with 5.1, 5.2, 5.3 and LuaJIT
- newlisp (tested with 10.7.5)
- Nim (tested with 0.17.0)
- NodeJS, requires sprintf (will be installed by
make
) - NodeJS_async, another NodeJS version which use async I/O, requires sprintf and async (will be installed by
make
) - NodeJS_cluster, uses multiple forked worker process via Node Cluster API
- OCaml
- FreePascal
- Perl
- Python, works with Python 2 & 3
- Python3_bytes
- R
- Racket
- Ruby and Rubinius
- Rust, >= 1.20
- Scala
- Vala, requires
glib2
(libglib-2.0
andlibgio-2.0
) - Tcl, >= 8.6
- Zig, tested with 0.9.1
Contributions are welcome! Improve current ones, or submit new one. But make sure your implementations meet the following requirements:
- Must be readable and maintainable
- Output exact the same format as other versions (but sorting may be unstable)
- Try to be efficient
- Please include a
Makefile
if appropriate - Don't forget to tell the compiler to optimize
This is tested on Arch Linux, with latest versions of compilers and interpreters available there at testing time. CPU is Intel(R) Core(TM) i7-7700HQ.
Updated at 2020-06-13:
Rust_parallel: top: 31.48, min: 29.66, avg: 32.83, max: 36.90, mdev: 1.86, cnt: 20 C++98_omp: top: 49.14, min: 45.32, avg: 53.43, max: 72.15, mdev: 6.00, cnt: 20 Crystal_process: top: 65.50, min: 64.67, avg: 69.53, max: 90.86, mdev: 6.32, cnt: 20 Go_goroutine: top: 96.19, min: 80.59, avg: 107.33, max: 152.03, mdev: 15.97, cnt: 20 Rust: top: 105.02, min: 104.25, avg: 106.21, max: 109.86, mdev: 1.64, cnt: 20 C++98: top: 142.99, min: 141.01, avg: 145.01, max: 151.68, mdev: 2.62, cnt: 20 C++17: top: 143.39, min: 141.34, avg: 145.20, max: 149.27, mdev: 2.15, cnt: 20 C++14_boost: top: 144.02, min: 142.48, avg: 147.36, max: 161.02, mdev: 4.98, cnt: 20 C++14: top: 144.63, min: 142.52, avg: 146.46, max: 151.17, mdev: 2.27, cnt: 20 C: top: 144.65, min: 141.69, avg: 152.78, max: 191.49, mdev: 11.96, cnt: 20 PHP: top: 145.38, min: 143.82, avg: 147.61, max: 156.60, mdev: 3.28, cnt: 20 Python3_mp: top: 157.63, min: 152.96, avg: 160.75, max: 167.09, mdev: 3.74, cnt: 20 C++11: top: 171.00, min: 168.77, avg: 172.47, max: 181.06, mdev: 2.43, cnt: 20 Cython: top: 181.13, min: 179.10, avg: 183.45, max: 192.59, mdev: 2.98, cnt: 20 Go: top: 193.06, min: 191.68, avg: 195.08, max: 201.55, mdev: 2.64, cnt: 20 Vala: top: 196.43, min: 193.41, avg: 200.22, max: 212.19, mdev: 4.70, cnt: 20 D_parallel_llvm: top: 196.72, min: 191.97, avg: 200.57, max: 213.42, mdev: 5.15, cnt: 20 D_parallel: top: 205.46, min: 199.73, avg: 208.67, max: 216.93, mdev: 4.29, cnt: 20 Crystal: top: 214.76, min: 210.48, avg: 217.29, max: 224.11, mdev: 3.25, cnt: 20 Crystal_fiber: top: 226.87, min: 225.04, avg: 233.10, max: 272.75, mdev: 12.50, cnt: 20 LuaJIT: top: 226.97, min: 224.28, avg: 231.18, max: 240.60, mdev: 4.86, cnt: 20 Haskell_parallel: top: 227.06, min: 216.14, avg: 235.88, max: 260.16, mdev: 11.77, cnt: 20 OCaml: top: 230.78, min: 229.04, avg: 233.81, max: 242.57, mdev: 3.83, cnt: 20 Python2: top: 232.30, min: 228.44, avg: 235.14, max: 245.36, mdev: 3.79, cnt: 20 NodeJS: top: 235.54, min: 233.22, avg: 239.51, max: 254.48, mdev: 5.11, cnt: 20 PyPy: top: 247.96, min: 244.07, avg: 253.04, max: 285.93, mdev: 8.61, cnt: 20 D_llvm: top: 249.79, min: 247.05, avg: 259.87, max: 312.30, mdev: 17.22, cnt: 20 Python3: top: 255.07, min: 254.20, avg: 260.64, max: 281.31, mdev: 7.91, cnt: 20 Python3_bytes: top: 257.99, min: 252.36, avg: 265.09, max: 289.54, mdev: 10.23, cnt: 20 D: top: 267.79, min: 266.07, avg: 272.18, max: 301.44, mdev: 7.70, cnt: 20 Nim: top: 279.93, min: 278.35, avg: 286.19, max: 314.88, mdev: 8.93, cnt: 20 Ruby: top: 281.40, min: 278.51, avg: 285.42, max: 296.61, mdev: 5.06, cnt: 20 Lua51: top: 286.97, min: 282.82, avg: 292.06, max: 316.65, mdev: 7.19, cnt: 20 Erlang: top: 290.70, min: 219.62, avg: 329.77, max: 393.73, mdev: 51.76, cnt: 20 Lua52: top: 294.91, min: 290.32, avg: 300.19, max: 322.82, mdev: 7.16, cnt: 20 Perl: top: 300.15, min: 296.57, avg: 307.49, max: 323.94, mdev: 8.76, cnt: 20 Lua53: top: 309.14, min: 304.81, avg: 314.05, max: 332.84, mdev: 6.66, cnt: 20 Haskell: top: 326.48, min: 323.48, avg: 331.62, max: 346.78, mdev: 6.34, cnt: 20 Chicken: top: 376.63, min: 370.26, avg: 382.90, max: 426.14, mdev: 11.16, cnt: 20 PyPy3_bytes: top: 409.92, min: 398.71, avg: 422.03, max: 468.93, mdev: 17.08, cnt: 20 FreePascal: top: 417.88, min: 415.39, avg: 423.13, max: 453.09, mdev: 8.20, cnt: 20 NodeJS_cluster: top: 422.85, min: 409.16, avg: 430.56, max: 444.07, mdev: 9.24, cnt: 20 CoffeeScript: top: 440.48, min: 420.74, avg: 469.86, max: 555.34, mdev: 38.53, cnt: 20 ChezScheme: top: 454.38, min: 451.57, avg: 459.67, max: 471.25, mdev: 6.15, cnt: 20 PyPy3: top: 456.18, min: 449.58, avg: 474.78, max: 521.61, mdev: 22.42, cnt: 20 Java: top: 462.47, min: 455.63, avg: 468.49, max: 478.00, mdev: 6.90, cnt: 20 Guile: top: 489.58, min: 478.95, avg: 499.54, max: 529.63, mdev: 13.28, cnt: 20 CoffeeScript_parallel: top: 500.05, min: 481.84, avg: 524.93, max: 588.15, mdev: 30.29, cnt: 20 NodeJS_async: top: 518.14, min: 484.02, avg: 548.72, max: 619.11, mdev: 36.99, cnt: 20 Tcl: top: 519.87, min: 504.80, avg: 529.65, max: 553.50, mdev: 12.06, cnt: 20 Dart_native: top: 622.26, min: 616.78, avg: 634.25, max: 675.66, mdev: 16.27, cnt: 20 CommonLisp_opt: top: 643.17, min: 638.69, avg: 654.79, max: 697.46, mdev: 14.71, cnt: 20 CommonLisp_old: top: 678.22, min: 669.22, avg: 688.15, max: 701.31, mdev: 11.21, cnt: 20 Julia: top: 709.08, min: 702.52, avg: 721.52, max: 753.88, mdev: 15.30, cnt: 20 Racket_compiled: top: 807.49, min: 799.71, avg: 820.90, max: 852.44, mdev: 15.17, cnt: 20 Racket: top: 809.93, min: 802.91, avg: 837.35, max: 970.74, mdev: 46.79, cnt: 20 CSharp: top: 828.85, min: 819.36, avg: 843.39, max: 905.66, mdev: 19.79, cnt: 20 Dart: top: 843.20, min: 829.84, avg: 861.74, max: 949.99, mdev: 27.52, cnt: 20 Scala: top: 944.85, min: 897.81, avg: 996.39, max: 1122.12, mdev: 4186.68, cnt: 20 Elixir: top: 1072.99, min: 1054.52, avg: 1096.13, max: 1242.46, mdev: 4186.40, cnt: 20 Bash_parallel: top: 1163.78, min: 1133.18, avg: 1219.09, max: 1340.50, mdev: 4186.69, cnt: 20 POSIX_dash: top: 1393.27, min: 1370.19, avg: 1412.92, max: 1461.04, mdev: 4074.64, cnt: 20 R: top: 1475.58, min: 1458.35, avg: 1498.45, max: 1583.44, mdev: 4074.68, cnt: 20 POSIX_bash: top: 1563.31, min: 1552.28, avg: 1574.53, max: 1605.96, mdev: 4074.59, cnt: 20 POSIX_zsh: top: 1593.08, min: 1578.51, avg: 1620.55, max: 1719.31, mdev: 4062.81, cnt: 19 Bash: top: 2350.38, min: 2223.25, avg: 2506.19, max: 2867.53, mdev: 3579.59, cnt: 13 PowerShell: top: 3695.72, min: 3680.86, avg: 3755.14, max: 3893.89, mdev: 2148.64, cnt: 8 OCaml_lwt: FAILED with No such file or directory (os error 2) Ruby_rubinius: FAILED with No such file or directory (os error 2)
Java is Oracle JDK. Ruby_rubinius is not included because no packages available for Arch Linux. OCaml_lwt one is broken at the time of running the benchmark.