let f0 x = x + 1
let f1 x = x * 3
let f2 = f0 >> f1
let f3 x = x |> f0 |> f1
let sw = Stopwatch()
sw.Reset()
sw.Start()
[1..10000] |> Seq.iter (fun n -> (f2 n) |> ignore )
sw.Stop()
printfn "%d" (sw.ElapsedMilliseconds)
sw.Reset()
sw.Start()
[1..10000] |> Seq.iter (fun n -> (f3 n) |> ignore )
sw.Stop()
printfn "%d" (sw.ElapsedMilliseconds)
Console.ReadKey() |> ignore
The result is, in release mode, the pipeline is almost 3 times faster than composition.
I run the code from Debug mode and release mode. And invoke the .EXE from file system. Please feel free to perform the same tests and give me feedback.
As suggested by Arseny Kapoulkine, I tried to use the Seq.map and then Seq.Length to force evaluation. Unfortunately, the result is similiar:
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()
sw.Reset()
sw.Start()
[1..10000] |> Seq.map (fun n -> (f2 n) |> ignore ) |> Seq.length |> ignore
sw.Stop()
printfn "f2 = %d" (sw.ElapsedMilliseconds)
sw.Reset()
sw.Start()
[1..10000] |> Seq.map (fun n -> (f3 n) |> ignore ) |> Seq.length |> ignore
sw.Stop()
printfn "f3 = %d" (sw.ElapsedMilliseconds)
System.Console.ReadKey() |> ignore
Really appreciate the feedback from Arseny!
the code he present is at http://fssnip.net/8e. The result shows the difference between composite and pipeline is very small.
Now seems that composite and pipeline are same.
I run the code from Debug mode and release mode. And invoke the .EXE from file system. Please feel free to perform the same tests and give me feedback.
As suggested by Arseny Kapoulkine, I tried to use the Seq.map and then Seq.Length to force evaluation. Unfortunately, the result is similiar:
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()
sw.Reset()
sw.Start()
[1..10000] |> Seq.map (fun n -> (f2 n) |> ignore ) |> Seq.length |> ignore
sw.Stop()
printfn "f2 = %d" (sw.ElapsedMilliseconds)
sw.Reset()
sw.Start()
[1..10000] |> Seq.map (fun n -> (f3 n) |> ignore ) |> Seq.length |> ignore
sw.Stop()
printfn "f3 = %d" (sw.ElapsedMilliseconds)
System.Console.ReadKey() |> ignore
Really appreciate the feedback from Arseny!
the code he present is at http://fssnip.net/8e. The result shows the difference between composite and pipeline is very small.
Now seems that composite and pipeline are same.


