Print swap usage per process. Implemented in various programming languages
Rust C++ Python Makefile Scheme JavaScript Other
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Bash Bash: quotes Aug 5, 2017
Bash_parallel Fix /proc/*/smaps string searches for compatibility with newer kernels Jun 8, 2016
C++11 C++11: fix fabs not declared Jun 30, 2016
C++14 C++14: fix vector error Jun 30, 2016
C++14_boost Revert "optimize read file" Jun 30, 2016
C++98 fixing GCC option "--std" to "-std" for all C/C++ versions Jan 10, 2015
C Use strtol() instead of atoi() for better pid detection. May 27, 2018
CSharp changed CSharp compiler from mcs to dmcs Jan 26, 2015
ChezScheme ChezScheme: fix output Jul 14, 2017
Chicken Use sprintf instead of format where possible; it's faster Aug 29, 2015
CoffeeScript CoffeeScript: exit with error on error Jan 26, 2015
CoffeeScript_parallel CoffeeScript: exit with error on error Jan 26, 2015
CommonLisp_old Fix /proc/*/smaps string searches for compatibility with newer kernels Jun 8, 2016
CommonLisp_opt Fix /proc/*/smaps string searches for compatibility with newer kernels Jun 8, 2016
Crystal Crystal: various fixes Jan 9, 2018
D D: fix Makefile Jan 10, 2015
D_parallel D_parallel: fix Aug 14, 2015
Dart Prevent trailing chars other than '\x00' being trimmed Mar 25, 2016
Elixir Elixir: avoid warning for function calls without parentheses Jul 14, 2017
Erlang Erlang: fix for format ~.0f no longer being valid Jul 14, 2017
FreePascal add FreePascal ver Jan 1, 2015
Go Go: replace sort.Sort with sort.Slices Oct 13, 2017
Go_goroutine fix bug in go version go1.9: fatal error: all goroutines are asleep -… Jan 23, 2018
Guile Guile: fix output Jul 14, 2017
Haskell Haskell: fix all hlint warnings and errors Aug 5, 2018
Haskell2 Haskell: fix all hlint warnings and errors Aug 5, 2018
Java remove UseAES which is enabled by default Jan 10, 2015
Julia Julia: doesn't need -f arg now Aug 6, 2018
Lua Lua strings doesn't support indexing? Jul 15, 2017
Nim Nim: update for current version Jul 14, 2017
NodeJS npm updated package.json and produced lock files Jul 13, 2017
NodeJS_async npm updated package.json and produced lock files Jul 13, 2017
NodeJS_cluster NodeJS: Cluster version May 7, 2016
OCaml update(ocaml): fix filesize output Jul 15, 2017
OCaml_lwt update(ocaml): use Lwt.Infix Jul 15, 2017
PHP 优化PHP版本的细节 Nov 7, 2017
POSIX_shell POSIX_shell: discards less stderr Aug 7, 2017
Perl Perl: fix formatting Jul 15, 2017
Python Python: use generator instead of for-loop; close files immediately Jan 10, 2015
Python3_bytes Fix bytes.__index__(...) == b'...' Oct 22, 2016
Python_mp Python3_mp: multiprocessing version using concurrent.futures Jan 24, 2018
R R: fix output Jul 14, 2017
Racket compile Racket code Dec 31, 2014
Ruby enable frozen string literal, revert comm[-1].ord.zero? May 2, 2016
Rust Rust: use unstable sort Oct 13, 2017
Rust_parallel Rust_parallel: update Dec 29, 2017
Scala add Makefile Mar 15, 2015
Tcl Tcl: fix formatting Jul 14, 2017
Vala add Vala version Jan 13, 2015
benchmark benchmark: clippy & update Jul 27, 2017
.gitignore Rust_parallel: update Dec 29, 2017
Makefile remove NodeJS_parallel: paralleljs is 4 years old Sep 13, 2017
README.md update README for Crystal Jan 9, 2018
bench.py sort result to avoid issues with unstable sorts Jul 15, 2017
benchmark.toml Python3_mp: multiprocessing version using concurrent.futures Jan 24, 2018
changes add results Jul 14, 2017
countlines add countlines script Jan 6, 2015
rankchange add results Jul 14, 2017
result-20160630.txt add results Jul 14, 2017
result-20170714.txt add results Jul 14, 2017
run_benchmark benchmark: add symlink to run benchmark Jan 5, 2015
test.toml benchmark: finally finished! Jan 6, 2015

README.md

swapview is a simple program to view processes' swap usage on Linux. This is intended to be a lilydjwg's version of Hello World program.

How to play

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

Implementions and their requirements

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
  • 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
  • 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, tested with 0.24.1
  • D, dmd or ldmd (LLVM version)
  • Dart
  • Elixir
  • Erlang
  • Go >=1.8
  • Guile >= 2.1
  • Haskell, requires haskell-strict
  • Haskell2, another better Haskell version using more dependencies
  • Java, >= Java 8
  • Lua, requires lua-filesystem, works with 5.1, 5.2, 5.3 and LuaJIT
  • 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 and libgio-2.0)
  • Tcl, >= 8.6

Contributions

Contributions are welcome! Improve current ones, or submit new one. But make sure your implementations meet the following requirements:

  1. Must be readable and maintainable
  2. Output exact the same format as other versions (but sorting may be unstable)
  3. Try to be efficient
  4. Please include a Makefile if appropriate
  5. Don't forget to tell the compiler to optimize

My Result

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 2017-07-14:

           Rust_parallel: top:   30.48, min:   27.76, avg:   32.48, max:   37.80, mdev:    2.78, cnt:  20
               C++98_omp: top:   31.24, min:   29.04, avg:   34.42, max:   49.48, mdev:    4.52, cnt:  20
            Go_goroutine: top:   68.30, min:   61.87, avg:   75.89, max:  142.91, mdev:   16.39, cnt:  20
                   C++14: top:   83.17, min:   82.23, avg:   84.71, max:   92.58, mdev:    2.76, cnt:  20
             C++14_boost: top:   83.58, min:   83.20, avg:   84.58, max:   91.00, mdev:    1.72, cnt:  20
                   C++98: top:   83.71, min:   83.09, avg:   85.19, max:   91.48, mdev:    2.44, cnt:  20
                    Rust: top:   91.45, min:   90.81, avg:   93.08, max:   99.38, mdev:    2.07, cnt:  20
                       C: top:   91.49, min:   90.49, avg:   93.41, max:   99.44, mdev:    2.53, cnt:  20
                   C++11: top:   91.81, min:   91.33, avg:   93.52, max:  102.80, mdev:    3.04, cnt:  20
                     PHP: top:   93.91, min:   93.37, avg:   94.98, max:   99.42, mdev:    1.47, cnt:  20
                   OCaml: top:  106.85, min:  105.75, avg:  109.34, max:  118.03, mdev:    3.37, cnt:  20
                     Nim: top:  109.28, min:  108.44, avg:  110.75, max:  117.43, mdev:    2.13, cnt:  20
         D_parallel_llvm: top:  111.25, min:  109.43, avg:  113.21, max:  117.26, mdev:    2.33, cnt:  20
              D_parallel: top:  116.77, min:  114.69, avg:  118.95, max:  125.45, mdev:    2.87, cnt:  20
                    PyPy: top:  126.23, min:  124.29, avg:  128.34, max:  134.07, mdev:    2.79, cnt:  20
                  D_llvm: top:  129.63, min:  128.52, avg:  131.32, max:  137.65, mdev:    2.41, cnt:  20
                  LuaJIT: top:  132.68, min:  131.31, avg:  134.36, max:  143.07, mdev:    2.57, cnt:  20
                      Go: top:  135.57, min:  132.37, avg:  139.25, max:  148.37, mdev:    4.50, cnt:  20
                       D: top:  146.30, min:  145.00, avg:  149.14, max:  159.02, mdev:    3.85, cnt:  20
                Haskell2: top:  150.92, min:  149.41, avg:  153.25, max:  164.60, mdev:    3.53, cnt:  20
                 Python2: top:  155.36, min:  152.26, avg:  158.55, max:  170.20, mdev:    4.60, cnt:  20
                    Vala: top:  159.55, min:  157.87, avg:  161.40, max:  166.52, mdev:    2.26, cnt:  20
                  Erlang: top:  163.00, min:  158.63, avg:  168.76, max:  181.77, mdev:    7.09, cnt:  20
                   Lua51: top:  166.58, min:  164.58, avg:  168.89, max:  181.71, mdev:    3.69, cnt:  20
                   Lua52: top:  168.48, min:  167.40, avg:  170.82, max:  178.11, mdev:    3.36, cnt:  20
           Python3_bytes: top:  174.30, min:  172.65, avg:  176.83, max:  181.64, mdev:    2.91, cnt:  20
                   Lua53: top:  180.20, min:  177.79, avg:  185.01, max:  199.41, mdev:    6.07, cnt:  20
                    Perl: top:  180.22, min:  177.30, avg:  182.21, max:  186.09, mdev:    2.44, cnt:  20
              FreePascal: top:  180.85, min:  179.35, avg:  184.23, max:  197.83, mdev:    4.84, cnt:  20
                 Python3: top:  181.72, min:  178.47, avg:  184.09, max:  189.67, mdev:    2.99, cnt:  20
                    Ruby: top:  199.82, min:  197.16, avg:  203.62, max:  218.32, mdev:    4.92, cnt:  20
                 Chicken: top:  234.69, min:  232.11, avg:  239.61, max:  248.39, mdev:    5.63, cnt:  20
             PyPy3_bytes: top:  238.55, min:  237.18, avg:  242.08, max:  253.68, mdev:    4.53, cnt:  20
                   Guile: top:  254.49, min:  249.14, avg:  260.40, max:  275.83, mdev:    7.12, cnt:  20
              ChezScheme: top:  265.63, min:  262.52, avg:  268.56, max:  278.53, mdev:    3.94, cnt:  20
                    Java: top:  291.35, min:  283.94, avg:  302.36, max:  324.82, mdev:   12.38, cnt:  20
                  NodeJS: top:  317.01, min:  314.61, avg:  321.04, max:  332.05, mdev:    4.71, cnt:  20
                    Dart: top:  329.39, min:  325.63, avg:  334.57, max:  351.19, mdev:    6.92, cnt:  20
           Ruby_rubinius: top:  359.76, min:  357.74, avg:  363.13, max:  373.02, mdev:    4.45, cnt:  20
          CommonLisp_opt: top:  360.57, min:  358.41, avg:  365.15, max:  378.44, mdev:    5.76, cnt:  20
                     Tcl: top:  367.38, min:  363.28, avg:  372.89, max:  388.57, mdev:    6.65, cnt:  20
          CommonLisp_old: top:  376.27, min:  371.99, avg:  379.66, max:  390.55, mdev:    4.33, cnt:  20
                   PyPy3: top:  384.12, min:  376.60, avg:  390.16, max:  401.39, mdev:    7.32, cnt:  20
            CoffeeScript: top:  414.40, min:  393.13, avg:  432.25, max:  466.42, mdev:   20.64, cnt:  20
   CoffeeScript_parallel: top:  451.12, min:  425.11, avg:  464.92, max:  491.52, mdev:   17.05, cnt:  20
            NodeJS_async: top:  454.78, min:  437.13, avg:  465.18, max:  489.06, mdev:   13.02, cnt:  20
         Racket_compiled: top:  510.97, min:  505.22, avg:  516.20, max:  527.69, mdev:    6.23, cnt:  20
                  Racket: top:  520.70, min:  515.11, avg:  525.28, max:  533.79, mdev:    5.87, cnt:  20
         NodeJS_parallel: top:  673.38, min:  664.38, avg:  687.60, max:  724.04, mdev:   16.32, cnt:  20
                   Scala: top:  719.27, min:  698.23, avg:  740.32, max:  815.95, mdev:   27.27, cnt:  20
           Bash_parallel: top:  769.14, min:  751.56, avg:  775.91, max:  791.40, mdev:    8.82, cnt:  20
                 Haskell: top: 1036.33, min: 1013.27, avg: 1048.70, max: 1090.21, mdev: 4186.25, cnt:  20
                  Elixir: top: 1097.32, min: 1075.24, avg: 1113.36, max: 1144.80, mdev: 4186.26, cnt:  20
                       R: top: 1141.37, min: 1120.69, avg: 1156.42, max: 1177.79, mdev: 4186.26, cnt:  20
                    Bash: top: 1368.00, min: 1323.22, avg: 1479.66, max: 1994.19, mdev: 4077.71, cnt:  20
              POSIX_dash: top: 1841.09, min: 1833.25, avg: 1851.09, max: 1881.68, mdev: 3897.64, cnt:  17
               POSIX_zsh: top: 2124.79, min: 2110.81, avg: 2134.32, max: 2156.40, mdev: 3841.56, cnt:  15
              POSIX_bash: top: 2200.64, min: 2195.09, avg: 2206.75, max: 2221.41, mdev: 3807.09, cnt:  14
                  CSharp: FAILED with entity not found
                   Julia: FAILED with entity not found