Skip to content

Instantly share code, notes, and snippets.

View pelletier's full-sized avatar

Thomas Pelletier pelletier

View GitHub Profile
"""Python script that automates the benchmarking of Go utf8.Valid function over
small inputs.
This script will clone the Go repository, build the Go toolchain, and run the
utf8.Valid benchmarks over small inputs, both on the CL and its parent, and plot
the time per operation.
Requirements:
- Python 3
#include <immintrin.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
const char mask_bytes[] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
;; Display the assembly generated by the Go compiler of the code at current line in an emacs buffer.
;;
;; Navigate to a line of go code, then M-x my/go-show-asm.
(defun my/go-show-asm ()
(interactive)
(let* ((p (buffer-file-name))
(out-b "*go-show-asm*")
(needle (concat p ":" (number-to-string (line-number-at-pos)))))
(if (string-suffix-p ".go" p)
(progn
@pelletier
pelletier / avx2.go
Last active January 5, 2022 21:44
AVX2 right shift cross lanes fill with zeroes
// Go AVO code that generates a right shift cross lanes with zeroes fill when offset is known and less than 16 bytes.
Comment("Shift right that works if remaining bytes >= 16")
VPMOVQU(Mem{Base: d}, currentBlockY)
zeroes := YMM()
VPXOR(zeroes, zeroes, zeroes)
src1 := YMM()
# Script to generate performance graph for utf8.Valid.
# Takes output of go test -bench as stdin.
#
# make && go test ./utf8 -run=None -bench=BenchmarkValid|tee out.txt
# python plot.py < out.txt
# open data.png
import fileinput
import re
@pelletier
pelletier / document.go
Created October 23, 2021 19:45
Proposal for document editing structure API for go-toml/v2.
// Package document provides tools for manipulating the structure of TOML
// documents.
//
// While github.com/pelletier/go-toml provides efficient functions to transform
// TOML documents to and from usual Go types, this package allows you to create
// and modify the structure of a TOML document.
//
// Comments
//
// Most structural elements of a Document can have comments attached to them.
@pelletier
pelletier / issues.sh
Created September 16, 2021 21:36
Local copy of GitHub issues
gh issue list --json number,title,body -t "{{range .}}
---
## {{.number}} - {{.title}}
{{.body}}
{{end}}"|sed 's/\r//g' > issues.md
@pelletier
pelletier / me.go
Last active August 5, 2021 21:15
Don't do this at work!
package main
import (
"reflect"
"unsafe"
)
// Safe version to do this.
func ReadOnlyChanFromSlice(s []string) <-chan string {
c := make(chan string, len(s))
@pelletier
pelletier / benchmarking.md
Last active June 3, 2021 13:03
Benchmarking Go on AMD

While benchmarking https://github.com/pelletier/go-toml/tree/v2, I decided to play with CPU frequency scaling, to eliminate some noise in the benchmarks.

Running on the following:

goos: linux
goarch: amd64
cpu: AMD Ryzen 9 5950X 16-Core Processor
kernel: 5.12.8-300.fc34.x86_64