Skip to content

Commit 072d76e

Browse files
committed
Add a section about metrics in the Quickstart
1 parent f2fc7ff commit 072d76e

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

docs/Quickstart.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,40 @@ Almost any sorter can be passed to any adapter, with a few exceptions:
164164

165165
The specific restrictions are all documented in the adapters descriptions.
166166

167+
## Metrics
168+
169+
[Metrics][metrics] are a special kind of sorter adapters that can be used to retrieve information about about, such as the number of comparisons performed by a sorter, or the time it took to sort a collection. They are used together with the [metrics tools][metrics-tools] from the library utilities.
170+
171+
* Count the number of comparisons performed by a comparison sort:
172+
```cpp
173+
#include <vector>
174+
#include <cpp-sort/metrics/comparisons.h>
175+
#include <cpp-sort/sorters/slab_sorter.h>
176+
177+
int main()
178+
{
179+
auto sorter = cppsort::metrics::comparisons<cppsort::slab_sorter>{};
180+
std::vector<int> collection = { /* ... */ };
181+
auto comps = sorter(collection);
182+
std::print("slabsort perform {} comparisons", comps.value());
183+
}
184+
```
185+
186+
* Compute the time it takes to sort a collection:
187+
```cpp
188+
#include <vector>
189+
#include <cpp-sort/metrics/running_time.h>
190+
#include <cpp-sort/sorters/mel_sorter.h>
191+
192+
int main()
193+
{
194+
auto sorter = cppsort::metrics::running_time<cppsort::mel_sorter>{};
195+
std::vector<int> collection = { /* ... */ };
196+
auto comps = sorter(collection);
197+
std::print("melsort took {}", comps.value());
198+
}
199+
```
200+
167201
## Two-step sorting
168202

169203
Sometimes the information is not represented as simple collection of class instances, but as [parallel arrays][parallel-arrays] (also known as structure of arrays). To sort those, **cpp-sort** provides components for two-step sorting of random-access collections:
@@ -212,8 +246,10 @@ The previous sections describe some of the main tools provided by **cpp-sort** b
212246

213247
[cmake]: https://cmake.org/
214248
[conan]: https://conan.io/
215-
[merge-sorter]: Sorters.md#merge_sorter
216249
[measures-of-disorder]: Measures-of-disorder.md
250+
[merge-sorter]: Sorters.md#merge_sorter
251+
[metrics]: Metrics.md
252+
[metrics-tools]: Miscellaneous-utilities.md#metrics-tools
217253
[numpy-argsort]: https://numpy.org/doc/stable/reference/generated/numpy.argsort.html
218254
[parallel-arrays]: https://en.wikipedia.org/wiki/Parallel_array
219255
[pdq-sorter]: Sorters.md#pdq_sorter

0 commit comments

Comments
 (0)