I know this is almost an old story by now, but it’s the first time I’ve been able to produce any numbers myself. :)
Recently, I rewrote into F# a super simple data transferring app that I’d built for work last fall in C#. There’s not much to it: I grab data from a couple different databases, smash it together in multiple and occasionally bizarre ways, and send it on to its new database home. It’s a perfect use case for F#.
I ran into a couple issues along the way with the SQLEntityConnection and SQLDataConnection type providers.
First, a “mapping of CLR type to EDM type is ambiguous” error. I was using the SQLEntityConnection type provider for all the connections, but Entity Framework doesn’t allow mapping from two databases with any of the same table names.
So, I switched to using the SQLDataConnection type provider. For one database, it worked like a charm. (Progress!) A second one, not so much. I was confronted with somewhere near 680 schema errors. Eeek. After much (MUCH) random flailing about, I discovered that setting StoredProcedures = false for the connections rights everything. I worked out the rest of the code in a few hours this morning. Awesome!
First: during the rewrite, I noticed that I was actually processing tremendously more data than I needed. Heh, oops? This wasn’t as obvious in the C# code, and I’d apparently glossed over it. Going back and fixing this in the C# version actually brought the total processing time down to about 7 minutes (7:14.119 to be exact) from a couple hours.
70% less time!
Second, the longest part of the app, somewhat obviously and by far, was the middle step of processing the data. For the F# version, I used an Array.Parallel.partition to split out and then process what I needed. That, and a couple other details brought the total app time down to nearly 2 minutes (2:24.145.)
25% less code!
Third and finally, I ran a line count in C# (VS shows 140 lines of code, I’m guessing that doesn’t count brackets? Because that seems way too low for 2 projects and 15 total files.) The F# version is 103.
F# is the best ever.
Times, btw, are DateTime.Now differences from the first line of main, until just before the final line is printed to the console. Nothing fancy.