This blog created for F# Advent 2016 (English)
Full source code can be found here
- 2016-12-10
- New performance test - Anthony Lloyd (@AnthonyLloyd) suggested that I compare against Prime.Vmap.
| import os | |
| def del_empty_dirs(s_dir,f): | |
| b_empty = True | |
| for s_target in os.listdir(s_dir): | |
| s_path = os.path.join(s_dir, s_target) | |
| if os.path.isdir(s_path): | |
| if not del_empty_dirs(s_path): | |
| b_empty = False |
| #! /usr/bin/python | |
| # | |
| # Church numerals in Python. | |
| # See http://en.wikipedia.org/wiki/Church_encoding | |
| # | |
| # Vivek Haldar <[email protected]> | |
| # | |
| # https://gist.github.com/2438498 | |
| zero = lambda f: lambda x: x |
| open System | |
| open System.Collections.Generic | |
| [<Struct>] | |
| type Pair<'a when 'a: equality> = | |
| val v: 'a | |
| val w: 'a | |
| new(x,y)= {v=x;w=y} | |
| type Tone = | |
| | Rest = 0 | |
| | GbelowC = 196 | |
| | A = 220 | |
| | Asharp = 233 | |
| | B = 247 | |
| | C = 262 | |
| | Csharp = 277 | |
| | D = 294 | |
| | E = 330 |
| //inspired by http://stackoverflow.com/a/2812306/637783 | |
| type NullCoalesce = | |
| static member Coalesce(a: 'a option, b: 'a Lazy) = match a with Some a -> a | _ -> b.Value | |
| static member Coalesce(a: 'a Nullable, b: 'a Lazy) = if a.HasValue then a.Value else b.Value | |
| static member Coalesce(a: 'a when 'a:null, b: 'a Lazy) = match a with null -> b.Value | _ -> a | |
| let inline nullCoalesceHelper< ^t, ^a, ^b, ^c when (^t or ^a) : (static member Coalesce : ^a * ^b -> ^c)> a b = | |
| ((^t or ^a) : (static member Coalesce : ^a * ^b -> ^c) (a, b)) |
| module Huffman | |
| open System | |
| open System.IO | |
| type bit = bool | |
| type path = bit list | |
| type BinaryTreeNode = | |
| | Leaf of byte * frequency:int |
| type json = | |
| | Number of float | |
| | String of string | |
| | Boolean of bool | |
| | Array of json list | |
| | Object of (string * json) list | |
| | Null | |
| static member (?) (this,name:string) = | |
| match this with | |
| | Object xs -> xs |> List.find (fst >> (=) name) |> snd |
| namespace CommonStuff | |
| open Microsoft.FSharp.Reflection | |
| open System | |
| open System.Text | |
| open System.Collections.Generic | |
| open System.Linq | |
| open System.Drawing | |
| open System.Windows.Forms |
This blog created for F# Advent 2016 (English)
Full source code can be found here
Full source code can be found here
It is well-known that a hard disk has a long delay from that we request the data to that we get the data. Usually we measure the hard disk latency in milliseconds which is an eternity for a CPU. The bandwidth of a hard disk is decent good as SSD:s today can reach 1 GiB/second.
What is less known is that RAM has the same characteristics, bad latency with good bandwidth.
You can measure RAM latency and badndwidth using Intel® Memory Latency Checker. On my machine the RAM latency under semi-high load is ~120 ns (The 3r:1w bandwidth is 16GiB/second). This means that the CPU on my machine has to wait for ~400 cycles for data, an eternity.