Skip to content

Commit e23fd5c

Browse files
committed
docs: improve code readability showing perf gains
Two improvements here: 1. It's better to show the slowest first. 2. It's better to not 'open Nessos.Streams', and use the namespace explicitly. It took me a minute to wrap my head around this code, so I think with these 2 improvements, other will understand it a bit better the first time they read it.
1 parent 9371deb commit e23fd5c

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

docs/content/index.fsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,10 @@ For simple pipelines we have observed performance improvements of a factor of fo
3838
Important performance tip: Make sure that FSI is running with 64-bit option set to true and fsproj option prefer 32-bit is unchecked.
3939
*)
4040

41-
open Nessos.Streams
42-
4341
let data = [|1..10000000|] |> Array.map int64
4442

4543
// Sequential
4644

47-
// Real: 00:00:00.044, CPU: 00:00:00.046, GC gen0: 0, gen1: 0, gen2: 0
48-
data
49-
|> Stream.ofArray
50-
|> Stream.filter (fun x -> x % 2L = 0L)
51-
|> Stream.map (fun x -> x + 1L)
52-
|> Stream.sum
53-
5445
// Real: 00:00:00.264, CPU: 00:00:00.265, GC gen0: 0, gen1: 0, gen2: 0
5546
data
5647
|> Seq.filter (fun x -> x % 2L = 0L)
@@ -63,22 +54,29 @@ data
6354
|> Array.map (fun x -> x + 1L)
6455
|> Array.sum
6556

57+
// Real: 00:00:00.044, CPU: 00:00:00.046, GC gen0: 0, gen1: 0, gen2: 0
58+
data
59+
|> Nessos.Streams.Stream.ofArray
60+
|> Nessos.Streams.Stream.filter (fun x -> x % 2L = 0L)
61+
|> Nessos.Streams.Stream.map (fun x -> x + 1L)
62+
|> Nessos.Streams.Stream.sum
63+
6664
// Parallel
6765
open FSharp.Collections.ParallelSeq
6866

69-
// Real: 00:00:00.017, CPU: 00:00:00.078, GC gen0: 0, gen1: 0, gen2: 0
70-
data
71-
|> ParStream.ofArray
72-
|> ParStream.filter (fun x -> x % 2L = 0L)
73-
|> ParStream.map (fun x -> x + 1L)
74-
|> ParStream.sum
75-
7667
// Real: 00:00:00.045, CPU: 00:00:00.187, GC gen0: 0, gen1: 0, gen2: 0
7768
data
7869
|> PSeq.filter (fun x -> x % 2L = 0L)
7970
|> PSeq.map (fun x -> x + 1L)
8071
|> PSeq.sum
8172

73+
// Real: 00:00:00.017, CPU: 00:00:00.078, GC gen0: 0, gen1: 0, gen2: 0
74+
data
75+
|> Nessos.Streams.ParStream.ofArray
76+
|> Nessos.Streams.ParStream.filter (fun x -> x % 2L = 0L)
77+
|> Nessos.Streams.ParStream.map (fun x -> x + 1L)
78+
|> Nessos.Streams.ParStream.sum
79+
8280
(**
8381
## References
8482

0 commit comments

Comments
 (0)