Yes, for particular scenarios. droitfintech's fset library and new utilities introduced in this library offer measurable performance improvements across a wide range of conditions.
Clojure's set namespace prioritizes straightforward, idiomatic
implementations with variadic arguments.
We'll use the Criterium benchmarking facility to objectively measure the evaluation times of a range of scenarios. Our test sets will contain one to one-million elements. While spanning that range, we'll investigate the effects of overlap (i.e., the sizes of the unions and intersections) between the two input sets.
Overall, fset and this library's third variant, designated alt 3 demonstrate 10-40% speedup over Clojure's
implementations. For the latter, the cost is more complex implementation and missing variadics.
This upper trio of results involve operating on two sets containing the same number of elements, from one to one-million. The first chart shows full overlap, the middle shows half overlap, and the lower shows no overlap between the elements of the two sets. Each data point represents computing the union, the intersection, the left-difference, and the right-difference.
fset (gold circles) and alt 3 (purple squares) demonstrate a modest, but consistent, 20-40% speedup over the core
implementation (red triangles).
In contrast to the upper trio of charts where both sets were the same size, these lower two charts explore what happens when the two sets are substantially different sizes.
The first of the two lower charts shows timings when the left-hand set size is fixed at one-million elements while the right-hand set ranges from one to one-million elements. Again, the two alternative implementations (gold circles and purple squares) provide modest speedups compared to the core implementation (red triangles).
The second of the two lower charts shows timings when the left-hand set size is always one-thousand times larger than the right-hand set. Again, the alternative implementations show modest 15-25% speedups.
| arg, n | ||||
|---|---|---|---|---|
| version | 1000 | 10000 | 100000 | 1000000 |
| alt 1 | 1.4e-04±2.0e-06 | 1.5e-04±2.0e-06 | 2.3e-04±5.5e-06 | 1.3e-03±7.4e-05 |
| alt 2 | 1.4e-04±3.9e-06 | 1.4e-04±2.6e-06 | 2.2e-04±3.2e-06 | 1.3e-03±8.1e-05 |
| alt 3 | 1.4e-04±1.5e-06 | 1.5e-04±2.2e-06 | 2.2e-04±2.3e-06 | 1.0e-03±1.0e-05 |
| alt 4 | 1.3e-04±2.5e-06 | 1.4e-04±6.8e-07 | 2.2e-04±3.3e-06 | 1.4e-03±1.1e-04 |
| core | 1.4e-04±1.2e-06 | 1.4e-04±2.2e-06 | 2.2e-04±1.6e-06 | 1.3e-03±3.4e-05 |
| fset | 1.4e-04±2.1e-06 | 1.5e-04±1.9e-06 | 2.0e-04±1.5e-06 | 1.1e-03±1.0e-05 |
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |