Skip to content

Instantly share code, notes, and snippets.

View dim's full-sized avatar

Dimitrij Denissenko dim

View GitHub Profile

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

module RedisCluster
def self.crc16(bytes)
crc = 0
bytes.each_byte{|b|
crc = ((crc<<8) & 0xffff) ^ XMODEMCRC16Lookup[((crc>>8)^b) & 0xff]
}
crc
end
def self.slot(key)
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "Sorry, please run with sudo."
exit 1
fi
echo "deb http://binaries.erlang-solutions.com/debian `lsb_release -c | cut -f2` contrib" | tee /etc/apt/sources.list.d/esl-erlang.list
wget -O - http://binaries.erlang-solutions.com/debian/erlang_solutions.asc | apt-key add -
aptitude update
/* mtest8.c - memory-mapped database tester/toy */
/*
* Copyright 2013 Dimitrij Denissenko, Black Square Media
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
@dim
dim / redis-bitpos-benchmark.rb
Created October 1, 2013 08:10
Integration benchmark for redis BITPOS command
# Integration benchmark for redis BITPOS command
require 'redis'
require 'benchmark'
random = Random.new(1)
redis = Redis.new timeout: 60
bitlen = 10_000
tmpkey = "__rb__bs__"
server = File.expand_path('../src/redis-server', __FILE__)
{
"IAB1": "Arts & Entertainment",
"IAB1-1": "Books & Literature",
"IAB1-2": "Celebrity Fan/Gossip",
"IAB1-3": "Fine Art",
"IAB1-4": "Humor",
"IAB1-5": "Movies",
"IAB1-6": "Music",
"IAB1-7": "Television",
"IAB2": "Automotive",
# "Performance Scalability of a Multi-Core Web Server", Nov 2007
# Bryan Veal and Annie Foong, Intel Corporation, Page 4/10
fs.file-max = 5000000
net.core.netdev_max_backlog = 400000
net.core.optmem_max = 10000000
net.core.rmem_default = 10000000
net.core.rmem_max = 10000000
net.core.somaxconn = 100000
net.core.wmem_default = 10000000
net.core.wmem_max = 10000000
export function sum(
forSomeReasonThisIsAVeryLongVariableName1: number,
forSomeReasonThisIsAVeryLongVariableName2: number,
): number {
return (
forSomeReasonThisIsAVeryLongVariableName1 +
forSomeReasonThisIsAVeryLongVariableName2
);
}
@dim
dim / s2-cell-sizes.md
Created May 20, 2019 12:46
S2 Geometry Cell Sizes
@dim
dim / Makefile
Last active November 25, 2019 13:15
Go(lang) non-cryptographic hash benchmark
default: bench
bench:
go test -run=NONE -bench=. -benchmem