|
| 1 | +# C++11 vs Rust comparison |
| 2 | + |
| 3 | +## Intro |
| 4 | + |
| 5 | +The goal of this project is to understand programming idioms of Rust, and |
| 6 | +roughly measure Rust performance compared to C++11. For this purpose several |
| 7 | +well known algorithmic problems were considered. The problems were inspired and |
| 8 | +evolved from great computer science course "Algorithms: Theory & Practice" on |
| 9 | +Stepik paltform. Here the link to the course: |
| 10 | +https://stepik.org/course/217/syllabus . |
| 11 | + |
| 12 | +## Problems |
| 13 | + |
| 14 | +Here is short overview of the programming problems considered in the project. |
| 15 | +More detailed description of each task could be found in the tasks' folders. |
| 16 | + |
| 17 | +`huffman_encoding` and `huffman_decoding` are about of building optimal prefix |
| 18 | +code for the given message and decoding it back. These problems are about to |
| 19 | +work with priority queque (heap data structure), binary tree and hash map. |
| 20 | +Particular realisations on Rust and C++11 relies on standard libraries' |
| 21 | +realisation of hash map and priority queue implementing only binary tree to |
| 22 | +solve the problem. Complexity is O(N) for building the code. |
| 23 | + |
| 24 | +`binary_search` is quite well known and straightforward algorithm for searching |
| 25 | +of the particular value in a sorted array. Here is no significant distinctions |
| 26 | +in realisations. Complexity is O(logN). |
| 27 | + |
| 28 | +`mergesort` algorithm of sorting is implemented in non-recursion way in order |
| 29 | +to avoid stack overflow. Complexity is O(N logN). |
| 30 | + |
| 31 | +`levenshtein` distance is usually used to quantify the difference between two |
| 32 | +strings. The algorithm is implemented in dynamic prgramming manner. Complexity is O(N^2). |
| 33 | + |
| 34 | +## Folders overview |
| 35 | + |
| 36 | +Each problem can be found in the folder with the same name. In each folder here |
| 37 | +are `main.cpp` and `main.rs` source codes which is solving the described |
| 38 | +problems in C++11 and Rust. Also here is `Makefile` in each folder to compile |
| 39 | +the programs, prepare test data and perform performance measures. The common |
| 40 | +part of the `Makefile` can be found in `common/common.make`. |
| 41 | + |
| 42 | +Also each problem's folder contains `generator` project on Rust which is |
| 43 | +dedicated to generate input data for prgrams for testing purposes. |
| 44 | + |
| 45 | +Although one can find brief overview of the problems above, in the particular |
| 46 | +folder here is `README.md` with more formal problem descriptions and notes. |
| 47 | + |
| 48 | +## Performance testing set up |
| 49 | + |
| 50 | +Each problem has Make scenario with 4 rules: `main_rust`, `main_cpp`, `gen` and |
| 51 | +`bench`. First two are about compiling the programs. Every program recieves its |
| 52 | +input on `stdin` and write results in `stdout`. `gen` will prepare test data: |
| 53 | +three input sets `inp_low`, `inp_mid`, `inp_hi` with increasing problem sizes. |
| 54 | +Generally, `inp_low` contains smallest inputs, and `inp_hi` contains millions |
| 55 | +of entities and it usually takes few seconds to solve the problem of a such size. |
| 56 | +`bench` rule will call `common/compare_performace.sh` which will perform N (N = |
| 57 | +10) runs of every input on evety program and everage the result. Occasianally, |
| 58 | +here is not standard command line tool for measure the program runtime in |
| 59 | +milisecond resolution for Mac Os X and Linux.. Therefore in `common/measure` |
| 60 | +you will find a small rust program to meausre the runtime of another program. |
| 61 | +To run all steps in once, one can use `run_bench.sh`. It will take up to ten |
| 62 | +minutes to perform all compilations, generations and performance measures. |
| 63 | + |
| 64 | +## Compilation |
| 65 | + |
| 66 | +The next command line is used to compile C++ program: |
| 67 | + |
| 68 | +``` |
| 69 | + g++ -std=c++11 -O2 -o main_cpp main.cpp |
| 70 | +``` |
| 71 | + |
| 72 | +The next command line is used to compile Rust program: |
| 73 | + |
| 74 | +``` |
| 75 | + rustc -O --crate-name main_rust main.rs |
| 76 | +``` |
| 77 | + |
| 78 | + |
| 79 | +## Requirements |
| 80 | + |
| 81 | +One needs to run Mac Os X or Linux with installed to PATH GNU C++ compiler or Clang and Rust. By the author the presented project was tested with the next softwares: |
| 82 | + |
| 83 | +``` |
| 84 | +> rustc -V |
| 85 | +Rustc 1.20.0 (f3d6973f4 2017-08-27) |
| 86 | +
|
| 87 | +> g++ -v |
| 88 | +... |
| 89 | +gcc version 7.2.0 |
| 90 | +``` |
| 91 | + |
| 92 | +## License |
| 93 | + |
| 94 | +Actually here is no any type of restrictions on the materials in this repository. Anyone can do anything with the source code and results. |
0 commit comments