Skip to content

Instantly share code, notes, and snippets.

View maciej's full-sized avatar

Maciej Biłas maciej

View GitHub Profile
@maciej
maciej / hello.txt
Created April 13, 2023 20:43
Hello
Hello, Gist!
(this Gist is used for testing purposes)
@maciej
maciej / 0_bufbuf.md
Last active November 3, 2022 08:33
Impact of buffer size on line-splitting bufio.Scanner in Go

Go sets the default buffer size of na new bufio.Scanner to 4096 bytes. I've scanned a ~155MB file with an average line length of 62 bytes with smaller and larger buffer sizes. Here are the results running on a 2019 x86 MacBookPro:

file size: 155605069
lines: 2501619
avg line length: 62.20
  1024: 182.103886ms
 2048: 116.351501ms
@maciej
maciej / collision.py
Last active January 21, 2021 13:41 — forked from zadam/collision.py
Calculate birthday paradox (chance of collision) for very large numbers
#!/usr/bin/python
# This is used for calculating of birthday paradox for large values
# We're using approximation explained here: http://preshing.com/20110504/hash-collision-probabilities/
# Beware that approximation isn't very precise at smaller params N and K, but gets more precise with large numbers
# see https://docs.python.org/3/library/decimal.html#module-decimal
from decimal import *
# setting decimal precision
@maciej
maciej / signalling_init.go
Last active July 12, 2020 09:38
Signalling concurrent initialisation in Go
package main
import (
"sync"
"sync/atomic"
"testing"
)
func BenchmarkClosedChannel(b *testing.B) {
c := make(chan struct{})
@maciej
maciej / go_panic.go
Created December 9, 2019 09:42
Go Puzzler #3
package main
import (
"fmt"
"time"
)
func main() {
defer func() {
if r := recover(); r != nil {
package main
import "fmt"
func defer1() {
var s = "Hello!"
defer fmt.Println(s)
s = "Ahoy!"
}
@maciej
maciej / redis-hll-size.md
Last active March 30, 2023 19:03
Redis HLL size

Redis HLL has a 16 bytes header:

  • 8 bytes are used to cache the set cardinality
  • 3 are not used
  • 4 are used to store the magic "HYLL"
  • 1 is used to represent the type of the set (sparse or dense)
struct hllhdr {
 char magic[4]; /* "HYLL" */
package main
import (
"bufio"
"github.com/mediocregopher/radix/v3"
"github.com/mediocregopher/radix/v3/resp"
"net"
"testing"
)
#!/usr/bin/env fish
for f in (ls)
set -lx ff (echo -n $f | sed 's/\\\/\//g')
set -lx df (dirname $ff)
if test "$df" != "."
mkdir -p $df
mv $f $ff
end
end
@maciej
maciej / benchcmp.txt
Created January 14, 2019 09:40
Roaring Go 1.11 compared to Go 1.12beta2
⨯ benchcmp go1.11.txt go1.12beta2.txt
benchmark old ns/op new ns/op delta
BenchmarkRealDataParOr/census-income_srt-8 184208 176304 -4.29%
BenchmarkRealDataParOr/census-income-8 237498 242349 +2.04%
BenchmarkRealDataParOr/census1881_srt-8 403731 426420 +5.62%
BenchmarkRealDataParOr/census1881-8 441110 460445 +4.38%
BenchmarkRealDataParOr/dimension_003-8 2436382 2124177 -12.81%
BenchmarkRealDataParOr/dimension_008-8 867978 927777 +6.89%
BenchmarkRealDataParOr/dimension_033-8 322745 338295 +4.82%
BenchmarkRealDataParOr/uscensus2000-8 1181339 1447223 +22.51%