During the workshop I followed I learned the following handy directive #time that can be used in F# Interactive.
Executing the #time directive will enable basic profiling.
Letās try the code below in F# interactive(FSI):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#time | |
let strings = [| "Machine"; "Learning"; "with"; "F#"; "is"; "fun" |] | |
// We can transform it into a new array, | |
// containing the length of each string: | |
let lengths = Array.map (fun (s:string) -> s.Length) strings |
This will produce the following output:
--> Timing now on
Real: 00:00:00.000, CPU: 00:00:00.000, GC gen0: 0, gen1: 0, gen2: 0
val strings : string [] = [|"Machine"; "Learning"; "with"; "F#"; "is"; "fun"|]
val lengths : int [] = [|7; 8; 4; 2; 2; 3|]>
We get the real time and CPU time, as well as some information about garbage collection in generations 0, 1 and 2.
To disable it again you can execute the #time directive another time.