Created
September 28, 2017 18:06
-
-
Save mikeash/a6ebc8cc4cb630c1893fd2909bb11d86 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Foundation | |
class MutableBox<T> { | |
var value: T | |
init(_ initialValue: T) { | |
value = initialValue | |
} | |
} | |
class Unboxed { | |
var d: [Int: [Int: Set<Int>]] = [:] | |
func run() { | |
d[0] = [:] | |
d[0]?[0] = [] | |
let pi = ProcessInfo.processInfo | |
var last = pi.systemUptime | |
for i in 0... { | |
let now = pi.systemUptime | |
print(i, now - last) | |
last = now | |
d[0]?[0]?.insert(i) | |
} | |
} | |
} | |
class Boxed { | |
var d: [Int: [Int: MutableBox<Set<Int>>]] = [:] | |
func run() { | |
d[0] = [:] | |
d[0]?[0] = MutableBox([]) | |
let pi = ProcessInfo.processInfo | |
var last = pi.systemUptime | |
for i in 0... { | |
let now = pi.systemUptime | |
print(i, now - last) | |
last = now | |
d[0]?[0]?.value.insert(i) | |
} | |
} | |
} | |
//Unboxed().run() | |
Boxed().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment