Skip to content

Instantly share code, notes, and snippets.

View zzl0's full-sized avatar

zzl zzl0

View GitHub Profile
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
class memoized(object):
'''Decorator. Caches a function's return value each time it is called.
If called later with the same arguments, the cached value is returned
(not reevaluated).
'''
def __init__(self, func):
self.func = func
self.cache = {}
def __call__(self, *args):
@zzl0
zzl0 / hw1.scala
Last active August 29, 2015 13:57
1. 编写一个BankAccount类,加入deposit和withdraw方法,和一个只读的balance属性。
class BankAccount(val balance: Double) {
def deposit(amount: Double): BankAccount = {
require(amount > 0)
new BankAccount(balance + amount)
}
def withdraw(amount: Double): BankAccount = {
require(amount > 0 && amount <= balance)