Skip to content

Instantly share code, notes, and snippets.

View garybernhardt's full-sized avatar

Gary Bernhardt garybernhardt

View GitHub Profile
bench "paths", :without_gc => true, :gc_time => true do
PATHS[0, 1000].each { |choice| Score.score(choice, "x" * 16) }
end
Output:
...!.!.!.!..............................................
filtering paths
Before: | --X----------------------- |
After: | ---------X-------------------------|
This tool is used to compare microbenchmarks across two versions of code. It's
paranoid about nulling out timing error, so the numbers should be meaningful.
It runs the benchmarks many times, scaling the iterations up if the benchmark
is extremely short, and it nulls out its own timing overhead while doing so. It
reports results graphically with a text interface in the terminal.
You first run it with --record, which generates a JSON dotfile with runtimes
for each of your benchmarks. Then you change the code and run again with
--compare, which re-runs and generates comparison plots between your recorded
and current times. In the example output, I did a --record on the master
#!/usr/bin/env bash
main() {
if [ ! -p .test-commands ]; then
mkfifo .test-commands
fi
while true; do
cmd=$(cat .test-commands)
if [[ $cmd == "" ]]; then
failbowl:rubies(master) $ git l
* 65cc7ef (41 seconds) <Gary Bernhardt> (HEAD, master) Merge branch 'activate_command_cleanup'
|\
| * f4ced72 (2 minutes) <Gary Bernhardt> extract variables
| * f2760be (3 minutes) <Gary Bernhardt> File.join instead of string interpolation
| * 94b8df5 (5 minutes) <Gary Bernhardt> activate command's imperative part is in activate!
|/
* 9291243 (7 minutes) <Gary Bernhardt> Merge branch 'ruby_info_cleanup'
|\
| * b7cb944 (9 minutes) <Gary Bernhardt> indentation
puts "export #{vars.map { |k, v| %{#{k}="#{v}"} }.join(" ")}"
# Goal: put a non-Rails-aware Ruby library using normal `require`s in
# lib/sim. Have it transparently reloaded between requests like Rails app
# code is.
#
# The code here goes inside of your configure block in
# config/environments/development.rb. There are two parts, commented inline.
# Reload code whenever the simulator changes.
config.watchable_dirs["lib/sim"] = [:rb]
config.watchable_files << "lib/sim.rb"
failbowl:~(master) $ cabal list --installed hunit
* HUnit
Synopsis: A unit testing framework for Haskell
Default available version: 1.2.5.2
Installed versions: 1.2.5.2
Homepage: http://hunit.sourceforge.net/
License: BSD3
failbowl:~(master) $ echo 'import HUnit' | runhaskell
inbox_blobs() {
git ls-tree -r master | grep 'INBOX' | awk '{print $3}' | sort
}
diff <(cd ../Gmail && inbox_blobs) <(inbox_blobs) | grep '<\|>' | while read marker hash; do
echo "$marker $(git show $hash | grep -m 1 '^Subject:')"
done | sort
#!/bin/bash
/usr/bin/env ruby --disable-gems <(cat <<'EOF'
puts "ruby code goes here"
EOF)
$ echo '#!/bin/ls /' > foo
$ ./foo
./foo
/:
bin boot dev etc home initrd.img lib lib64 lost+found media mnt opt proc root run sbin selinux srv sys tmp usr var vmlinuz
$ echo '#!/bin/ls / /' > foo
$ ./foo
/bin/ls: cannot access / /: No such file or directory