Skip to content

Instantly share code, notes, and snippets.

View simonhf's full-sized avatar

Simon Hardy-Francis simonhf

View GitHub Profile
@simonhf
simonhf / lmdb-perf-test.txt
Created March 21, 2014 01:34
Performance testing lmdb with 16 concurrent processes & 70 million keys
# # ssh to Rackspace 16 vCPU box to perf test lmdb
# # try to do a similar multi-process test to the one at https://github.com/simonhf/sharedhashfile
# # note: could not figure out how to insert more that 70 million keys; other test inserts 100 million keys
# # note: created lmdb hash file on /dev/shm to make it a fairer test
# # note: as you can see below, inserting is extremely slow but lmdb only claims that reading is lighting fast :-)
# # note: the 'mix' 2% update, 98% read test shows that read performance gets bogged down if reading & writing :-(
# # note: not sure if I am using the lmdb API is the optimum way so please forgive me & suggest changes!
# # note: comments to feedback@sharedhashfile.com please
# apt-get update
# apt-get install build-essential
@simonhf
simonhf / main.c
Created August 12, 2014 23:51
How to use macros to name unique variables?
#include <stdio.h>
#define TOKENPASTE2(x, y) x ## y
#define TOKENPASTE(x, y) TOKENPASTE2(x, y)
#define FOO TOKENPASTE(var_, __LINE__)
#define BAR __LINE__
void
main(void)
{
@simonhf
simonhf / -
Last active August 29, 2015 14:09 — forked from anonymous/-
MongoDB shell version: 2.6.5
connecting to: lichess
[
{
"_id" : "rynNl407",
"p1" : {
"ai" : 8
},
"ps" : BinData(0,"AAABAGBgBmYAAAAADQbFAAAADg5gAAAAAOkA4LAAAAA="),
"s" : 31,
@simonhf
simonhf / persistent_pipes_linux.md
Last active September 10, 2015 17:26 — forked from CAFxX/persistent_pipes_linux.md
Persistent pipes/circular buffers for Linux

Persistent "pipes" in Linux

In a project I'm working on I ran into the requirement of having some sort of persistent FIFO buffer or pipe in Linux, i.e. something file-like that could accept writes from a process and persist it to disk until a second process reads (and acknowledges) it. The persistence should be both across process restarts as well as OS restarts.

AFAICT unfortunately in the Linux world such a primitive does not exist (named pipes/FIFOs do not persist

@simonhf
simonhf / hardest.c
Last active January 2, 2018 01:53
experiments with tarantool transactions, fibers, and C box_insert (because Lua string performance sucks)
#include "module.h"
#define MP_SOURCE 1 /* define in a single .c/.cc file */
#include "msgpuck.h"
// https://tarantool.org/doc/tutorials/c_tutorial.html?highlight=stored%20procedure
// CPATH=/usr/include/tarantool/:/usr/include/ gcc -shared -o hardest.so -fPIC hardest.c
char * key_format = "the quick brown fox jumped over the lazy dog the qu %07u ick brown fox ";
char * field_2 = "'{\"0\":{\"1234567890\": 320, \"1234567890\": 1303}}'";
@simonhf
simonhf / 1-cache-line.c
Last active October 26, 2016 00:54
1 cache line fetch per hash table read simulation experimentation lab
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <unistd.h>
#include <murmurhash3.h>
// gcc -O3 -I. -o 1-cache-line 1-cache-line.c murmurhash3.c && ./1-cache-line
@simonhf
simonhf / cache-line-example.c
Last active February 1, 2024 23:30
Experiment with __builtin_prefetch()
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/time.h>
#include <locale.h>
#define NUMBYTES (1024*1024*1024)
char bytes[NUMBYTES];
@simonhf
simonhf / Chain.java
Last active October 4, 2022 16:18
C versus CPP versus Java; the performance failings of naive OO
//package com.dnene.josephus;
// $ javac Person.java Chain.java && java Chain
public class Chain
{
private Person first = null;
public Chain(int size)
{
@simonhf
simonhf / _C_vs_Golang.md
Last active July 26, 2019 22:13
C vs Golang in the context of run time performance considering compile time optimization ability with constant folding for debugging

Let's say you know C and are thinking about learning Golang. Let's also say that you prefer not to use a debugger [1]. This probably means you need to create a debug version of your Golang code. A way to do that is with constant folding [2], for example:

const constDebug = 0

if (1 == constDebug) { debugCode() } // if() compiled away due to constant folding
@simonhf
simonhf / _golang_tftpd.md
Last active September 9, 2019 04:28
Performance experiments with Golang, epoll, C, and tftp protocol

Time-boxed (AKA over the weekend) investigation into creating a Golang tftpd server

Disclaimer 1: Don't know much about tftp protocol.

Disclaimer 2: Don't know much about Golang.

Step 1: Learn about tftp protocol

Read up on the tftp protocol