Skip to content

Instantly share code, notes, and snippets.

@mikeash
Created September 28, 2017 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeash/a6ebc8cc4cb630c1893fd2909bb11d86 to your computer and use it in GitHub Desktop.
Save mikeash/a6ebc8cc4cb630c1893fd2909bb11d86 to your computer and use it in GitHub Desktop.
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