0 people like it.
Like the snippet!
Pipeline vs composition performance
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
|
open System.Diagnostics
let f0 x = x + 1
let f1 x = x * 3
let f2 = f0 >> f1
let f3 x = x |> f0 |> f1
let sw = Stopwatch()
let N = 1000000
Seq.init 1 id |> Seq.map f2 |> Seq.length |> ignore
sw.Reset()
sw.Start()
Seq.init N id |> Seq.map f2 |> Seq.length |> ignore
sw.Stop()
printfn "f2 = %d" (sw.ElapsedMilliseconds)
sw.Reset()
sw.Start()
Seq.init N id |> Seq.map f3 |> Seq.length |> ignore
sw.Stop()
printfn "f3 = %d" (sw.ElapsedMilliseconds)
System.Console.ReadKey() |> ignore
|
namespace System
namespace System.Diagnostics
val f0 : x:int -> int
Full name: Script.f0
val x : int
val f1 : x:int -> int
Full name: Script.f1
val f2 : (int -> int)
Full name: Script.f2
val f3 : x:int -> int
Full name: Script.f3
val sw : Stopwatch
Full name: Script.sw
Multiple items
type Stopwatch =
new : unit -> Stopwatch
member Elapsed : TimeSpan
member ElapsedMilliseconds : int64
member ElapsedTicks : int64
member IsRunning : bool
member Reset : unit -> unit
member Restart : unit -> unit
member Start : unit -> unit
member Stop : unit -> unit
static val Frequency : int64
...
Full name: System.Diagnostics.Stopwatch
--------------------
Stopwatch() : unit
val N : int
Full name: Script.N
module Seq
from Microsoft.FSharp.Collections
val init : count:int -> initializer:(int -> 'T) -> seq<'T>
Full name: Microsoft.FSharp.Collections.Seq.init
val id : x:'T -> 'T
Full name: Microsoft.FSharp.Core.Operators.id
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>
Full name: Microsoft.FSharp.Collections.Seq.map
val length : source:seq<'T> -> int
Full name: Microsoft.FSharp.Collections.Seq.length
val ignore : value:'T -> unit
Full name: Microsoft.FSharp.Core.Operators.ignore
Stopwatch.Reset() : unit
Stopwatch.Start() : unit
Stopwatch.Stop() : unit
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
property Stopwatch.ElapsedMilliseconds: int64
type Console =
static member BackgroundColor : ConsoleColor with get, set
static member Beep : unit -> unit + 1 overload
static member BufferHeight : int with get, set
static member BufferWidth : int with get, set
static member CapsLock : bool
static member Clear : unit -> unit
static member CursorLeft : int with get, set
static member CursorSize : int with get, set
static member CursorTop : int with get, set
static member CursorVisible : bool with get, set
...
Full name: System.Console
System.Console.ReadKey() : System.ConsoleKeyInfo
System.Console.ReadKey(intercept: bool) : System.ConsoleKeyInfo
More information