Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this F# code so slow?

People also ask

What F means in chat?

The Brief: Typing "f" into a chat is a way for people to "pay their respects" to something or someone.

What does F mean on Instagram story?

Summary of Key Points. "Drooling" is the most common definition for :F on Snapchat, WhatsApp, Facebook, Twitter, Instagram, and TikTok. :F.

When did the F word become offensive?

Historians generally agree that "fuck" hit its stride in the 15th and 16th centuries as a familiar word for sexual intercourse, and from there it evolved into the vulgarity we know today.

Where did the F word come from?

The F-word was recorded in a dictionary in 1598 (John Florio's A Worlde of Wordes, London: Arnold Hatfield for Edw. Blount). It is remotely derived from the Latin futuere and Old German ficken/fucken meaning 'to strike or penetrate', which had the slang meaning to copulate.


The problem is that the min3 function is compiled as a generic function that uses generic comparison (I thought this uses just IComparable, but it is actually more complicated - it would use structural comparison for F# types and it's fairly complex logic).

> let min3(a, b, c) = min a (min b c);;
val min3 : 'a * 'a * 'a -> 'a when 'a : comparison

In the C# version, the function is not generic (it just takes int). You can improve the F# version by adding type annotations (to get the same thing as in C#):

let min3(a:int, b, c) = min a (min b c)

...or by making min3 as inline (in which case, it will be specialized to int when used):

let inline min3(a, b, c) = min a (min b c);;

For a random string str of length 300, I get the following numbers:

> levenshtein str ("foo" + str);;
Real: 00:00:03.938, CPU: 00:00:03.900, GC gen0: 275, gen1: 1, gen2: 0
val it : int = 3

> levenshtein_inlined str ("foo" + str);;
Real: 00:00:00.068, CPU: 00:00:00.078, GC gen0: 0, gen1: 0, gen2: 0
val it : int = 3