Skip to content

Instantly share code, notes, and snippets.

@phemmer
phemmer / client.c
Created May 18, 2014 09:29
cerver/client code to test maximum number of connections
/*
Opens multiple connections to 127.0.0.1:2222 until an error occurs.
It displays a counter of the number of open connections so far.
As soon as an error occurs, it prints the error and exits.
The counter will be the number of open connections at the time of error.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
@phemmer
phemmer / gist:569105182a025746cb99
Created January 23, 2015 12:59
swarm-docker launch
#!/bin/bash
num_dockers=3
docker_image=dind
########################################
deferred=()
deferred_pid=$BASHPID
run_deferred() {
if [[ "$deferred_pid" != $BASHPID ]]; then
package main
import (
sm "github.com/phemmer/sawmill"
)
type mymap map[string]interface{}
type mystruct struct {
Foo string
Bar string
@phemmer
phemmer / bench_test.go
Created February 25, 2015 14:31
string concat benchmark
package main
import (
"fmt"
"testing"
)
const str = "s"
var bslice = []byte(str)
@phemmer
phemmer / bench_test.go
Created April 10, 2015 16:31
defer vs no defer
package main
import (
"testing"
)
type conn struct{}
func (c *conn) Close() {}
func (c *conn) Value() bool {
@phemmer
phemmer / lock_test.go
Created April 11, 2015 01:05
golang locking benchmarks
package main
import (
"sync"
"sync/atomic"
"testing"
)
var v int64
@phemmer
phemmer / 97g.go
Created April 15, 2015 19:41
mysql schema benchmark
// import tmp/97g
package main
import (
"database/sql"
"fmt"
"log"
"math/rand"
"strconv"
"time"
@phemmer
phemmer / callers_test.go
Last active August 29, 2015 14:19
golang callers benchmark
package main
import (
"runtime"
"testing"
)
var callers [100]uintptr
var callersCopy []uintptr
#include <stdlib.h>
#include <stdio.h>
int main() {
char *buf;
int i;
for (i = 0; i < 2048; i++) {
buf = (char *) malloc(1024*1024);
printf("buf=%p\n", buf);
@phemmer
phemmer / main.go
Created April 22, 2015 02:29
golang db scan comparison
package main
import (
"database/sql"
"encoding/json"
"fmt"
_ "github.com/mattn/go-sqlite3"
)