Skip to content

Instantly share code, notes, and snippets.

View ericychoi's full-sized avatar

Eric Choi ericychoi

  • SendGrid
  • Anaheim, CA
View GitHub Profile
@ericychoi
ericychoi / base64_test.go
Last active February 26, 2016 01:08
Benchmark and compare regexp vs base64 decoding for a given payload
package base64Benchmark
import (
"bytes"
"encoding/base64"
"flag"
"io/ioutil"
"os"
"regexp"
"testing"
@ericychoi
ericychoi / parse.pl
Last active January 15, 2016 18:56
SImple MIME Parser from STDIN
#!/opt/perl/bin/perl
use MIME::Parser;
use strict;
use warnings;
my $parser = MIME::Parser->new();
$parser->output_to_core(1);
$parser->decode_bodies(1);
@ericychoi
ericychoi / mp3tag.pl
Last active August 29, 2015 14:25
A Perl script that sets mp3 tags based on filename
use MP3::Tag;
use Encode qw/encode decode/;
use Data::Dumper;
use strict;
use warnings;
# run it in the same directory as mp3s
# sets mp3v2 tags based on file names (assumes filenames are encoded UTF-8, which should be)
#
# filename example: 085. 2PM-01-우리집.mp3
@ericychoi
ericychoi / httpsink.js
Created February 20, 2015 01:10
Simple HTTP POST Sink
var http = require('http');
http.createServer(function(request,response){
var body = "";
request.on('data', function(chunk) { body += chunk; });
request.on('end', function() {
console.log('POST: ' + body + "\n");
response.writeHead(200);
response.end();
});
}).listen(8000);

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