Skip to content

Instantly share code, notes, and snippets.

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns                     on recent CPU
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  =   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 4X memory

# == Schema Information
#
# Table name: tasks
#
# id :integer not null, primary key
# date :date
# task :text
# tid :string(255)
# actual_time_taken :float
# billable_time_taken :float
@sahilsk
sahilsk / gist:7bf6d18a0b936dd7bf24
Last active November 1, 2015 05:39 — forked from remy/gist:350433
local storage polyfill
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
db.campaigns.find(
{
target_region :
{ $near :
{
$geometry: { type: "Point", coordinates: [-80.190262, 25.774252] },
$maxDistance: 50000000
}
}
}
curl -s https://api.github.com/orgs/twitter/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}'
curl -s https://api.github.com/orgs/twitter/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}'
@sahilsk
sahilsk / example_usage.js
Last active August 29, 2015 14:13
topic based simple async pub-sub implementation
//Example Usage
var seeker1 = function(msg) {
console.log("seeker1 called: " + msg);
}
var seeker2 = function(msg) {
console.log("seeker2 called: " + msg);
}
@sahilsk
sahilsk / nginx
Last active August 29, 2015 14:14 — forked from vdel26/nginx
nginx init script
#!/bin/sh
#
# chkconfig: 2345 55 25
# Description: Nginx init.d script, put in /etc/init.d, chmod +x /etc/init.d/nginx
# For Debian, run: update-rc.d -f nginx defaults
# For CentOS, run: chkconfig --add nginx
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
@sahilsk
sahilsk / unicorn.rb
Last active August 29, 2015 14:14 — forked from chasseurmic/unicorn.rb
# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end