Created
July 19, 2012 14:52
-
-
Save t0yv0/3144484 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.Collections.Generic | |
type Cache<'T> private () = | |
static let d = Dictionary<string,'T>() | |
static member Format(format: Printf.StringFormat<'T>) : 'T = | |
let key = format.Value | |
match d.TryGetValue(key) with | |
| true, r -> r | |
| _ -> | |
let r = sprintf format | |
d.Add(key, r) | |
r | |
let sprintf' fmt = | |
Cache<_>.Format(fmt) | |
#time | |
for i in 1 .. 10000 do | |
ignore (sprintf "%i" 15) | |
for i in 1 .. 10000 do | |
ignore (sprintf' "%i" 15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment