diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-08-30 18:35:23 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-08-30 18:35:23 +0200 |
| commit | 5e3b4b6c21d33b28e60ce976479339f72d544a6c (patch) | |
| tree | 0e5a101d4944e7dd5a99606344b6a6807a9a5606 /src/blog/2024-04-30-taming-cpp-motivation/taming-cpp-motivation.md | |
| parent | d3f0841cfdd229ff16b8a230117737a435fc7a56 (diff) | |
| download | sebastiano.tronto.net-5e3b4b6c21d33b28e60ce976479339f72d544a6c.tar.gz sebastiano.tronto.net-5e3b4b6c21d33b28e60ce976479339f72d544a6c.zip | |
Switch from stagit to cgit
Diffstat (limited to 'src/blog/2024-04-30-taming-cpp-motivation/taming-cpp-motivation.md')
| -rw-r--r-- | src/blog/2024-04-30-taming-cpp-motivation/taming-cpp-motivation.md | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/blog/2024-04-30-taming-cpp-motivation/taming-cpp-motivation.md b/src/blog/2024-04-30-taming-cpp-motivation/taming-cpp-motivation.md index 3181eb0..532a0dd 100644 --- a/src/blog/2024-04-30-taming-cpp-motivation/taming-cpp-motivation.md +++ b/src/blog/2024-04-30-taming-cpp-motivation/taming-cpp-motivation.md | |||
| @@ -40,7 +40,7 @@ You can find the code I wrote in | |||
| 40 | 40 | ||
| 41 | To sort a list of a hundred million integers, in C we can use `qsort()` | 41 | To sort a list of a hundred million integers, in C we can use `qsort()` |
| 42 | from `stdlib.h` (see | 42 | from `stdlib.h` (see |
| 43 | [sort.c](https://git.tronto.net/taming-cpp/file/sort-benchmark/integers/sort.c.html)): | 43 | [sort.c](https://git.tronto.net/taming-cpp/tree/sort-benchmark/integers/sort.c)): |
| 44 | 44 | ||
| 45 | ``` | 45 | ``` |
| 46 | qsort(a, ARRAYSIZE, sizeof(int), compar); | 46 | qsort(a, ARRAYSIZE, sizeof(int), compar); |
| @@ -55,7 +55,7 @@ int compar(const void *x, const void *y) { | |||
| 55 | ``` | 55 | ``` |
| 56 | 56 | ||
| 57 | In C++ we can use `sort()` from `algorithm` (see | 57 | In C++ we can use `sort()` from `algorithm` (see |
| 58 | [sort.cpp](https://git.tronto.net/taming-cpp/file/sort-benchmark/integers/sort.cpp.html)): | 58 | [sort.cpp](https://git.tronto.net/taming-cpp/tree/sort-benchmark/integers/sort.cpp)): |
| 59 | 59 | ||
| 60 | ``` | 60 | ``` |
| 61 | std::sort(a, a+ARRAYSIZE, | 61 | std::sort(a, a+ARRAYSIZE, |
| @@ -69,7 +69,7 @@ instead of a comparison function. | |||
| 69 | Modern C++ also offers parallelized | 69 | Modern C++ also offers parallelized |
| 70 | version of common algorithms as part of the standard library, so if | 70 | version of common algorithms as part of the standard library, so if |
| 71 | we want to completely humiliate poor C we can use this (see | 71 | we want to completely humiliate poor C we can use this (see |
| 72 | [sort_parallel.cpp](https://git.tronto.net/taming-cpp/file/sort-benchmark/integers/sort_parallel.cpp.html)): | 72 | [sort_parallel.cpp](https://git.tronto.net/taming-cpp/tree/sort-benchmark/integers/sort_parallel.cpp)): |
| 73 | 73 | ||
| 74 | ``` | 74 | ``` |
| 75 | std::sort(std::execution::par, a, a+ARRAYSIZE, | 75 | std::sort(std::execution::par, a, a+ARRAYSIZE, |
| @@ -94,9 +94,9 @@ Even without parallelization, C++ is twice as fast as C! | |||
| 94 | You might think that C++ is somehow optimizing for integer | 94 | You might think that C++ is somehow optimizing for integer |
| 95 | sorting. But this is not the case, as demonstrated by a similar experiment | 95 | sorting. But this is not the case, as demonstrated by a similar experiment |
| 96 | with *pairs* of integers (see | 96 | with *pairs* of integers (see |
| 97 | [sort.c](https://git.tronto.net/taming-cpp/file/sort-benchmark/pairs/sort.c.html), | 97 | [sort.c](https://git.tronto.net/taming-cpp/tree/sort-benchmark/pairs/sort.c), |
| 98 | [sort.cpp](https://git.tronto.net/taming-cpp/file/sort-benchmark/pairs/sort.cpp.html) and | 98 | [sort.cpp](https://git.tronto.net/taming-cpp/tree/sort-benchmark/pairs/sort.cpp) and |
| 99 | [sort_parallel.cpp](https://git.tronto.net/taming-cpp/file/sort-benchmark/pairs/sort_parallel.cpp.html) | 99 | [sort_parallel.cpp](https://git.tronto.net/taming-cpp/tree/sort-benchmark/pairs/sort_parallel.cpp) |
| 100 | - I used a non-standard mixed lexicographic order to be reasonably sure the | 100 | - I used a non-standard mixed lexicographic order to be reasonably sure the |
| 101 | compiler does not come up with any ad-hoc optimization): | 101 | compiler does not come up with any ad-hoc optimization): |
| 102 | 102 | ||
