Skip to content

Instantly share code, notes, and snippets.

View mintisan's full-sized avatar

Jinhui-Lin mintisan

View GitHub Profile
@mintisan
mintisan / latency.txt
Created November 2, 2015 14:24 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
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
@mintisan
mintisan / coroutine.h
Created April 19, 2015 12:03
Coroutines in C
/* coroutine.h
*
* Coroutine mechanics, implemented on top of standard ANSI C. See
* http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html for
* a full discussion of the theory behind this.
*
* To use these macros to define a coroutine, you need to write a
* function that looks something like this.
*
* [Simple version using static variables (scr macros)]
@mintisan
mintisan / coroutine2.c
Created April 19, 2015 12:00
Tony Finch - Coroutines in less than 20 lines of standard C
/**
* From
* http://fanf.livejournal.com/105413.html
**/
#include <stddef.h>
#include <setjmp.h>
#include <stdlib.h>
#include <stdio.h>
@mintisan
mintisan / coroutine3.c
Created April 19, 2015 11:52
Coroutines in C with Arbitrary Arguments
/**
* From
* http://250bpm.com/blog:48
*
**/
#include <stdio.h>
#include <setjmp.h>
#include "stdlib.h"

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

@mintisan
mintisan / resume.c
Last active February 3, 2017 14:32 — forked from klange/_.md
#include <stdio.h>
#include <time.h>
typedef struct {
union {
char * company;
char * school;
char * project;
};
union {
@mintisan
mintisan / SHO.py
Last active August 2, 2016 12:30
A Simple Heuristic Optimization in Python
import numpy as np
import random
def sphere(x):
tmp = 0
for i,d in enumerate(x):
tmp += (d - 0.1*i)*(d - 0.1*i);
return tmp
class swarm(object):
@mintisan
mintisan / crc-ccitt.c
Last active August 29, 2015 14:07
crc_ccitt from Linux Kernel
#include "crc-ccitt.h"
// From : http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/include/linux/crc-ccitt.h?v=2.6.11.8#L11
static u16 crc_ccitt_byte(u16 crc, const u8 c)
{
return (crc >> 8) ^ crc_ccitt_table[(crc ^ c) & 0xff];
}