Skip to content

Instantly share code, notes, and snippets.

import sys
from operator import gt, ge
cmp = ge
def search(a, x):
print('search:', x)
i, j = 0, len(a)
while i < j:
h = (i+j) // 2
from timeit import Timer
cases = list(ln.split('#') for ln in
"""array('i', [0]) * n #arr * n
array('i', [0]*n) #arr(lst*n)
array('i', range(n)) #arr(range)
array('i', (0 for _ in range(n))) #arr(0 for range)
""".splitlines())
for i in range(8):
import timeit
import random
import array
setups = """xs = array('i', [0]) * n #array
xs = [0] * n #list
"""
# xs = [None] * n #list
# ^^^^ make no difference in timing
find -name '*.rs' -exec bash -c \
'wc -c $0; base64 -w0 < $0 | wc -c; ruby -r uri -e "p URI.encode_www_form_component(STDIN.read).size" < $0; echo' {} \;
@autf
autf / Makefile
Last active March 21, 2023 05:30
An offical example of embedding Python in C + an unofficial Makefile
run: pt
./pt
pt: printime.c
cc `python3-config --cflags` -o $@ $^ `python3-config --ldflags --embed`
clear:
rm -f pt