Skip to content

Instantly share code, notes, and snippets.

View chipbuster's full-sized avatar

Kevin Song chipbuster

  • University of Texas Austin
  • Austin, Texas
View GitHub Profile
@chipbuster
chipbuster / floating-point-precision-diverge.py
Created January 30, 2023 15:59
A Demonstration of Floating Point Precision in Python
# In principle, this should be simple enough to reconstruct on the fly
# In practice, every time I come back to it, it takes me 10-20 minutes
# to recall the correct sequence of operations to get the dang thing
# to diverge, so I'm going to gist this.
x = 1/3
print(f"Initially, x is {x}")
for _ in range(540):
x *= 4.0
x -= 1.0

Keybase proof

I hereby claim:

  • I am chipbuster on github.
  • I am chipbuster (https://keybase.io/chipbuster) on keybase.
  • I have a public key ASBnZyv4DYR2FoOozLHQHgGvlmYXFA8dskKdWyiBQTKl5wo

To claim this, I am signing this object:

@chipbuster
chipbuster / gen_paramsweep_segfaulting.jl
Created February 2, 2022 18:22
A Julia program which segfaults on x64 Arch, when running under 32 threads. Seems to segfault more often when caches are cold.
using Base.Threads
using Serialization
using Distributions
using LoopVectorization
function bin_data(data, lo, hi, nbins)
dx = (hi - lo) / nbins
bins = ((data .- lo) ./ dx) .|> floor
bins = UInt8.(bins)
clamp.(bins, UInt8(0), UInt8(nbins))
@chipbuster
chipbuster / benchmark_build.py
Last active March 4, 2024 21:19
Rust Compilation Benchmarks
# A script to automate the timings of Rust compilation benchmarks used at
# https://www.reddit.com/r/rust/comments/qgi421/doing_m1_macbook_pro_m1_max_64gb_compile/
import sys,os
import subprocess
import tempfile
import time
import json
# You need to have the wasm32-unknown-unknown target installed, use
# `rustup target install wasm32-unknown-unknown` to get it.
@chipbuster
chipbuster / benchmark_starship.sh
Last active June 10, 2020 18:35
Starship Speed Tester
#!/bin/bash
# Downloads, builds, installs, and runs timing tests for two starship and two git
# programs, using a small repo (starship), a medium repo (rust-lang) and a large
# repo (chromium) as test cases. Also has an option on Linux to use `sudo` to run
# tests with cold caches. This can be done either by waiting for the interactive
# dialog or by setting the envar `RUN_COLD_STARSHIP_TESTS` to any non-empty value
# Unfortunately, I do not know what packages need to be installed on your computer
# before you can successfully use this script. It's provided more as a starting

Halting Problem in Python

This particular example was derived from an SO post, though I know there's at least one website that precedes this post by a few years. There are other great examples that derive contradictions in other ways, such as this one.

Suppose I could write a python program that told me whether a

@chipbuster
chipbuster / mystery.py
Last active July 21, 2018 00:41
What does it doooooo?
#!/usr/bin/env python3
def g(f):
q = {}
def new(x):
if x not in q:
q[x] = f(x)
return q[x]
return new