Skip to content

Instantly share code, notes, and snippets.

View teivah's full-sized avatar
Building my newsletter: The Coder Cafe

Teiva Harsanyi teivah

Building my newsletter: The Coder Cafe
View GitHub Profile
package main
import (
"fmt"
"runtime"
)
func main() {
// Init
n := 1_000_000
t1 t2
Read InventorySize (100)
Read InventorySize (100)
Set InventorySize to 100 + 5 = 105
Set InventorySize to 100 + 10 = 110
Commit
Commit
t1 t2
Read A
Set A=1
Commit
...
Read A
t1 t2
Set A=0
Delete rows where A=0
Rollback
Commit
t1 t2
Set A=1
Set A=2
Set B=2
Set B=1
t1 t2
Set A=1
Set A=2
Set B=2
Set B=1
func concat(values []string) string {
total := 0
for i := 0; i < len(values); i++ {
total += len(values[i])
}
sb := strings.Builder{}
sb.Grow(total)
for _, value := range values {
_, _ = sb.WriteString(value)
Step map[int][128]byte map[int]*[128]byte
Allocate an empty map 0 MB 0 MB
Add 1 million elements 461 MB 182 MB
Remove all the elements and run a GC 293 MB 38 MB
type hmap struct {
B uint8 // log_2 of # of buckets
// (can hold up to loadFactor * 2^B items)
// ...
}
@teivah
teivah / map-2.go
Last active September 27, 2022 12:11
func main() {
n := 1_000_000
m := make(map[int][128]byte)
printAlloc()
for i := 0; i < n; i++ { // Adds 1 million elements
m[i] = [128]byte{}
}
printAlloc()