Skip to content

Instantly share code, notes, and snippets.

@manofstick
Created June 9, 2018 04:06
Show Gist options
  • Save manofstick/9b06efefe1396808611cf55e812c0ea9 to your computer and use it in GitHub Desktop.
Save manofstick/9b06efefe1396808611cf55e812c0ea9 to your computer and use it in GitHub Desktop.
type EnumA = A0 = 0 | A1 = 1 | A2 = 2 | A3 = 3 | A4 = 4 | A5 = 5 | A6 = 0x7
let getAnEnum i = match i &&& 7 with 0 -> EnumA.A0 | 1 -> EnumA.A1 | 2 -> EnumA.A2 | 3 -> EnumA.A3 | 4 -> EnumA.A4 | 5 -> EnumA.A5 | _ -> EnumA.A6
type R = {
GroupByKey : EnumA
OtherData : float
}
let data = [|
let r = System.Random 42
for i = 1 to 10000000 do
yield { GroupByKey = getAnEnum (r.Next()); OtherData = 42. }
|]
let total_time = System.Diagnostics.Stopwatch.StartNew ()
for i = 1 to 10 do
let sw = System.Diagnostics.Stopwatch.StartNew ()
let grouped =
data
|> Array.groupBy (fun d -> d.GroupByKey)
printf " iteration=%dms [" sw.ElapsedMilliseconds
grouped |> Array.iter (fun (key,items) -> printf "%A=%d;" key items.Length)
printfn "]"
printfn "total_time=%dms" total_time.ElapsedMilliseconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment