aboutsummaryrefslogtreecommitdiff
path: root/src/blog/2024-04-30-taming-cpp-motivation/taming-cpp-motivation.md
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-08-30 18:35:23 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2026-08-30 18:35:23 +0200
commit5e3b4b6c21d33b28e60ce976479339f72d544a6c (patch)
tree0e5a101d4944e7dd5a99606344b6a6807a9a5606 /src/blog/2024-04-30-taming-cpp-motivation/taming-cpp-motivation.md
parentd3f0841cfdd229ff16b8a230117737a435fc7a56 (diff)
downloadsebastiano.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.md12
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
41To sort a list of a hundred million integers, in C we can use `qsort()` 41To sort a list of a hundred million integers, in C we can use `qsort()`
42from `stdlib.h` (see 42from `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```
46qsort(a, ARRAYSIZE, sizeof(int), compar); 46qsort(a, ARRAYSIZE, sizeof(int), compar);
@@ -55,7 +55,7 @@ int compar(const void *x, const void *y) {
55``` 55```
56 56
57In C++ we can use `sort()` from `algorithm` (see 57In 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```
61std::sort(a, a+ARRAYSIZE, 61std::sort(a, a+ARRAYSIZE,
@@ -69,7 +69,7 @@ instead of a comparison function.
69Modern C++ also offers parallelized 69Modern C++ also offers parallelized
70version of common algorithms as part of the standard library, so if 70version of common algorithms as part of the standard library, so if
71we want to completely humiliate poor C we can use this (see 71we 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```
75std::sort(std::execution::par, a, a+ARRAYSIZE, 75std::sort(std::execution::par, a, a+ARRAYSIZE,
@@ -94,9 +94,9 @@ Even without parallelization, C++ is twice as fast as C!
94You might think that C++ is somehow optimizing for integer 94You might think that C++ is somehow optimizing for integer
95sorting. But this is not the case, as demonstrated by a similar experiment 95sorting. But this is not the case, as demonstrated by a similar experiment
96with *pairs* of integers (see 96with *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
101compiler does not come up with any ad-hoc optimization): 101compiler does not come up with any ad-hoc optimization):
102 102

Generated with cgit - Back to sebastiano.tronto.net