This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NOTES | |
"before" is Go version go1.19-dd97871282, before the switch jump tables commits | |
"after" is Go version go1.19-78bea702cd, after the switch jump tables commits | |
# GOAWK'S GO MICROBENCHMARKS | |
$ benchstat -sort=delta -geomean benchmarks_before.txt benchmarks_after.txt | |
name old time/op new time/op delta | |
IncrDecr-8 141ns ± 1% 160ns ± 2% +13.59% (p=0.008 n=5+5) | |
IfStatement-8 147ns ± 1% 157ns ± 2% +6.59% (p=0.008 n=5+5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"path/filepath" | |
) | |
func main() { | |
if len(os.Args) != 2 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Calculate the probability of generating a duplicate random number after | |
generating "n" random numbers in the range "d". | |
Usage: python birthday_probability.py n [d=365] | |
Each value can either be an integer directly, or in the format "2**x", where | |
x is the number of bits in the value. | |
For example, to calculate the probability that two people will have the same | |
birthday in a room with 23 people: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN { | |
FS = "," | |
} | |
{ | |
nf = csvify(fields) | |
for (i=1; i<=nf; i++) { | |
printf "|%s|\n", fields[i] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"strconv" | |
) | |
func main() { | |
http.HandleFunc("/multiply", func(w http.ResponseWriter, r *http.Request) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A little "Connect Four" game | |
package main | |
import ( | |
"bufio" | |
"flag" | |
"fmt" | |
"os" | |
"strconv" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package model | |
import ( | |
"database/sql" | |
"errors" | |
"fmt" | |
"reflect" | |
"sync" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Efficient sliding-window sorting of time-series data in CSV file. | |
Demo for http://stackoverflow.com/a/42398981/68707 | |
Tested on Python 3.5. | |
""" | |
import collections | |
import csv | |
import datetime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections, random, sys, textwrap | |
# Build possibles table indexed by pair of prefix words (w1, w2) | |
w1 = w2 = '' | |
possibles = collections.defaultdict(list) | |
for line in sys.stdin: | |
for word in line.split(): | |
possibles[w1, w2].append(word) | |
w1, w2 = w2, word |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Speed up os.walk() significantly by using file attributes that | |
FindFirst/Next give us instead of doing an extra stat(). Can also do the same | |
thing with opendir/readdir on Linux. | |
This is doubly useful when the user (caller of os.walk) is doing *another* | |
stat() to get say the file sizes. | |
On my tests (Windows 64-bit) our walk() is about 5x as fast as os.walk() for | |
large directory trees, and 9x as fast if you're doing the file size thing. | |
Note that these timings are "once it's in the cache", not first-time timings. |