From 0744c789210c661ff4f17017004ca72191648015 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Fri, 22 Jan 2016 15:33:08 +0800 Subject: [PATCH] docs: improve code readability showing perf gains Two improvements here: 1. It's better to show the slowest first. 2. Rather use type aliasing instead of namespace opening (before, the connection between `open Nessos.Streams` and Stream|ParStream was not so clear). It took me a minute to wrap my head around this code, so I think with these 2 improvements, others will understand it a bit better the first time they read it. --- docs/content/index.fsx | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/docs/content/index.fsx b/docs/content/index.fsx index adea386..3f767dd 100644 --- a/docs/content/index.fsx +++ b/docs/content/index.fsx @@ -38,19 +38,10 @@ For simple pipelines we have observed performance improvements of a factor of fo Important performance tip: Make sure that FSI is running with 64-bit option set to true and fsproj option prefer 32-bit is unchecked. *) -open Nessos.Streams - let data = [|1..10000000|] |> Array.map int64 // Sequential -// Real: 00:00:00.044, CPU: 00:00:00.046, GC gen0: 0, gen1: 0, gen2: 0 -data -|> Stream.ofArray -|> Stream.filter (fun x -> x % 2L = 0L) -|> Stream.map (fun x -> x + 1L) -|> Stream.sum - // Real: 00:00:00.264, CPU: 00:00:00.265, GC gen0: 0, gen1: 0, gen2: 0 data |> Seq.filter (fun x -> x % 2L = 0L) @@ -63,15 +54,18 @@ data |> Array.map (fun x -> x + 1L) |> Array.sum -// Parallel -open FSharp.Collections.ParallelSeq -// Real: 00:00:00.017, CPU: 00:00:00.078, GC gen0: 0, gen1: 0, gen2: 0 +type NStream = Nessos.Streams.Stream + +// Real: 00:00:00.044, CPU: 00:00:00.046, GC gen0: 0, gen1: 0, gen2: 0 data -|> ParStream.ofArray -|> ParStream.filter (fun x -> x % 2L = 0L) -|> ParStream.map (fun x -> x + 1L) -|> ParStream.sum +|> NStream.ofArray +|> NStream.filter (fun x -> x % 2L = 0L) +|> NStream.map (fun x -> x + 1L) +|> NStream.sum + +// Parallel +open FSharp.Collections.ParallelSeq // Real: 00:00:00.045, CPU: 00:00:00.187, GC gen0: 0, gen1: 0, gen2: 0 data @@ -79,6 +73,16 @@ data |> PSeq.map (fun x -> x + 1L) |> PSeq.sum + +type PStream = Nessos.Streams.ParStream + +// Real: 00:00:00.017, CPU: 00:00:00.078, GC gen0: 0, gen1: 0, gen2: 0 +data +|> PStream.ofArray +|> PStream.filter (fun x -> x % 2L = 0L) +|> PStream.map (fun x -> x + 1L) +|> PStream.sum + (** ## References