Hello!
I’m half-way through reading the book “Get Programming with F#”. As a fun exercise, I decided to go a little off-track and implement a program resembling the system utility tree
:
That’s because I wanted to play with a recursive type, which is a notion I first came upon while studying Elm.
Out of curiosity, I then decided to implement the same logic in Ocaml (beginner as well):
I basically copy/pasted the original F# code, then adapted the pieces bit by bit until the code compiled.
To my surprise, I found the Ocaml code 3 times faster!
Here’s the output of the tool trying to sift trough 175872
files. I piped the output into wc
in order to exclude from the measurement the slowness associated to writing to stdin (or printing to stdout).
Ocaml
$ time dune exec tree ~/code/explore/angular/ | wc -l
175872
real 0m2.131s
user 0m1.087s
sys 0m1.034s
F#
$ time ./bin/Release/net6.0/DiskUsage ~/code/explore/angular/ | wc -l
175872
real 0m6.776s
user 0m5.006s
sys 0m3.928s
System utility, for reference
$ time tree ~/code/explore/angular/ | wc -l
175875
real 0m1.156s
user 0m0.711s
sys 0m0.488s
I tried to inspect things via a profiler (from my IDE, without piping into wc
), but nothing jumped at me. I can see I’m spending most time printing and looping over the next directory which seems normal.
Is anything obvious jumping at you? Could you suggest me possible ways to improve performance?