-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
I would very much want that the documentation contains a minimal convincing example
(and that this would also be included in tests, so we can be sure that it works).
"Convincing" in the sense that
- running with
+RTS -N<k>
(for small k) visibly, and progressively, reduces execution time - code is readable and stand-alone (no fancy extra libraries)
For reference, I am using the following C# example (sum of bitcounts) in teaching
and I like that it has these properties:
- it's two one-liners (naive bitcount implementation, naive summation)
- parallelisation is trivial (add
.AsParallel()
) - effect is visible (cut execution time nearly in half)
- works out-of-the-box in
csharp
REPL
Func<int,int> bc = (int x) => { int c=0; while (x>0) { c += x%2 ; x >>= 1 ; } return c; }
Time(() => Console.WriteLine( Enumerable.Range(0,1<<27).Select(bc).Sum()))
1811939328
00:00:03.5504990
Time(() => Console.WriteLine( Enumerable.Range(0,1<<27).AsParallel().Select(bc).Sum()))
1811939328
00:00:02.1616790
If there is such an example (my naive use of parListChunk
does not seem to cut it) I'm happy to write it up as haddock and submit a PR.
NB - Sure I know (and discuss with students) that there are better implementations of bc
, and that sum-of-bitcounts (up to powers of two) has a closed form, so we don't actually need any of this...
AleXoundOS, declension, omnibs and thosakwe
Metadata
Metadata
Assignees
Labels
No labels