Inverted worker thread pool pattern from Rethinking Classical Concurrency Patterns
var sem = make(chan struct{}, limit)
func start() {
for _, task := range hugeSlice {
sem <- struct{}{}
Hello, Gist! | |
(this Gist is used for testing purposes) |
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
#!/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 |
package main | |
import ( | |
"sync" | |
"sync/atomic" | |
"testing" | |
) | |
func BenchmarkClosedChannel(b *testing.B) { | |
c := make(chan struct{}) |
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!" | |
} |
Redis HLL has a 16 bytes header:
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 |