lilydjwg / swapview-rosetta

Print swap usage per process. Implemented in various programming languages
493 stars 108 forks source link

Zig: initial implementation #173

Closed zhangkaizhao closed 2 years ago

zhangkaizhao commented 2 years ago

Tested with Zig 0.9.1 on Linux x86_64.

lilydjwg commented 2 years ago

Please write output to stdout.

Only the last null of cmdline should be removed. Others should be all replaced as spaces.

The program is a bit slow. Did you forget to compile it in optimized mode?

zhangkaizhao commented 2 years ago

Done:

I have added the --strip parameter for building the executable file. In my testing Linux box, this is a little slower than the Rust implementation for a small data set. Although Zig provides ReleaseSafe/ReleaseFast/ReleaseSmall build modes, I think it is better to use the ReleaseSafe build mode for most use cases. The ReleaseFast build mode maybe runs a little faster.

lilydjwg commented 2 years ago

Weird, it's significantly slower here:

           Rust_parallel: top:   88.06, min:   86.81, avg:   90.96, max:  109.33, mdev:    4.95, cnt:  20                                          
               C++98_omp: top:  132.12, min:  125.93, avg:  139.50, max:  161.16, mdev:    9.13, cnt:  20
                   C++98: top:  315.28, min:  311.04, avg:  320.05, max:  344.84, mdev:    7.29, cnt:  20                                          
                    Rust: top:  317.51, min:  313.31, avg:  325.72, max:  370.10, mdev:   13.01, cnt:  20
                   C++17: top:  324.03, min:  320.26, avg:  330.47, max:  354.35, mdev:    8.55, cnt:  20
                       C: top:  327.09, min:  320.33, avg:  337.83, max:  362.08, mdev:   13.02, cnt:  20
                   C++14: top:  332.56, min:  321.06, avg:  343.06, max:  381.00, mdev:   13.96, cnt:  20
                   C++11: top:  385.49, min:  376.63, avg:  395.65, max:  426.54, mdev:   12.92, cnt:  20
                     Zig: top:  975.72, min:  964.58, avg:  994.59, max: 1049.19, mdev: 4186.28, cnt:  20
zhangkaizhao commented 2 years ago

Oh! My bad skill beats Zig.

The trueth is that I am learning this language and there should be lots of places to improve.

lilydjwg commented 2 years ago

Never mind. This project is for language beginners and you can improve the implementation later. It's just Zig fails my expectation.

zhangkaizhao commented 2 years ago

I have fixed the build mode in #174. It should perform well now.