Skip to content

Instantly share code, notes, and snippets.

@y-lu
y-lu / latency.txt
Created October 27, 2018 04:52 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
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 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@y-lu
y-lu / eps2.R
Created June 20, 2017 19:10
R functions to generate and display plots directly on iTerm2 (requires two of my shell scripts on gist: imgcat2 and iterm2-dl2).
.eps = c()
eps2 = function(fn, code, width=10, height=10) {
if(is.na(fn) || fn=="") {
fn = tempfile("plot-",getwd(),".eps")
}
if(length(.eps)==0 || .eps[length(.eps)] != fn) {
.eps <<- c(.eps, fn)
}
setEPS()
postscript(fn,height=height,width=width)
@y-lu
y-lu / iterm-dl2.sh
Created June 20, 2017 19:06
Script to download file directly from within two nested tmux sessions on iTerm2. Another feature is the script would strip the leading path of the filename.
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: $(basename $0) file ..."
exit 1
fi
for fn in "$@"
do
if [ -r "$fn" ] ; then
[ -d "$fn" ] && { echo "$fn is a directory"; continue; }
#printf '\033]1337;File=name='`echo -n "$fn" | base64`";"
@y-lu
y-lu / imgcat2.sh
Created June 20, 2017 19:04
Display image from nested tmux session on iTerm2. This script adds extra escape sequence to make it work within exactly two nested tmux sessions.
#!/bin/bash
# tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
# <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
# only accepts ESC backslash for ST.
function print_osc() {
#if [[ $TERM == screen* ]] ; then
# if [[ .$TMUX != . ]] ; then
#printf "\033Ptmux;\033\033]"
echo -ne '\033Ptmux;\033\033Ptmux;\033\033\033\033]'