Skip to content

Instantly share code, notes, and snippets.

@luchuan
luchuan / latency.markdown
Created October 14, 2016 01:59 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

# coding: utf-8
import yappi
import threading
from pybloom import BloomFilter
TEST_KEYS_NUM = 1000000
KEYS = [i for i in range(TEST_KEYS_NUM)]
def golden_hash(value):
num = hash(value)
prime = 2654435761
return (num * prime) % (2 ** 32)
@luchuan
luchuan / fork-pr
Last active December 8, 2015 10:29
fork - pr 协作模式
主仓库: https://github.com/owner/repo.git
开发仓库:https://github.com/collaborator/repo.git
开发准备:
git clone https://github.com/collaborator/repo.git
git remote -v (看一下是否有添加 upstream)
git remote add upstream https://github.com/owner/repo.git (如果没有,添加一下)
git pull upstream branchname(与主仓库最新的代码合并一下)
本地开发:
# coding:utf-8
from random import randint, sample
from collections import Counter
from itertools import combinations
def gen_carts(items, n_cart):
n_items = len(items)
carts = []
with open('carts.txt', 'w') as f:
Process: Xcode [46662]
Path: /Applications/Xcode6-Beta.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 6.0 (6194.21)
Build Info: IDEFrameworks_KLONDIKE-6194021000000000~12
Code Type: X86-64 (Native)
Parent Process: launchd [901]
Responsible: Xcode [46662]
User ID: 501
// Playground - noun: a place where people can play
import Cocoa
func main() {
func _fib(x: Int, y: Int, i: Int) -> Int {
if i == 1 || i == 0 {
@luchuan
luchuan / Makefile
Created June 5, 2013 16:06
avr-gcc Makefile template
# ----------------------------------------------------------------------------
# Makefile based on WinAVR Makefile Template written by Eric B. Weddington,
# Jörg Wunsch, et al.
#
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
@luchuan
luchuan / spy.py
Created May 13, 2013 05:53
pypcap example
# coding:utf-8
import pcap
import dpkt
from datetime import datetime
pc = pcap.pcap()
pc.setfilter('tcp port 80')
for ptime, pdata in pc:
print datetime.fromtimestamp(ptime).strftime('%Y-%m-%d %H:%M:%S')#, pdata
p = dpkt.ethernet.Ethernet(pdata)
#!/usr/bin/env python
# Copyright (c) 2011 Adam Pingel
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.