Skip to content

Instantly share code, notes, and snippets.

@antocuni
antocuni / bench.cpp
Last active November 16, 2016 13:44
branch prediction
#include <algorithm>
#include <ctime>
#include <iostream>
int main(int argc, char** argv)
{
// Generate data
const unsigned arraySize = 32768;
int data[arraySize];
@antocuni
antocuni / pandasleak.py
Created March 2, 2017 14:10
pandas leak on pypy
import sys
import pandas as pd
import numpy as np
from plotmem import Plotmem
import gc
def leak1():
for i in Plotmem(100):
df = pd.DataFrame(
{'A': ['foo', 'bar'],
@antocuni
antocuni / bm_telco.py
Last active April 14, 2017 13:06
pypy telco benchmark
# coding: UTF-8
""" Telco Benchmark for measuring the performance of decimal calculations
http://www2.hursley.ibm.com/decimal/telco.html
http://www2.hursley.ibm.com/decimal/telcoSpec.html
A call type indicator, c, is set from the bottom (least significant) bit of the duration (hence c is 0 or 1).
A r, r, is determined from the call type. Those calls with c=0 have a low r: 0.0013; the remainder (‘distance calls’) have a ‘premium’ r: 0.00894. (The rates are, very roughly, in Euros or dollarates per second.)
A price, p, for the call is then calculated (p=r*n). This is rounded to exactly 2 fractional digits using round-half-even (Banker’s round to nearest).
A basic tax, b, is calculated: b=p*0.0675 (6.75%). This is truncated to exactly 2 fractional digits (round-down), and the total basic tax variable is then incremented (sumB=sumB+b).
@antocuni
antocuni / Makefile
Created December 20, 2017 17:05
elf-experiment
main: main.c greetings.c
gcc -c greetings.c
gcc -c main.c
gcc -o main greetings.o main.o
@antocuni
antocuni / conftest.py
Last active April 16, 2019 15:33
pytest capture bug
# if you uncomment this, the test works as expected
import dummy
@antocuni
antocuni / build-wheels.sh
Created May 6, 2020 13:48
pip/manylinux bug
#!/bin/bash
set -e
# Compile wheels
PYTHONS=(
cp27-cp27m
cp27-cp27mu
)
# remove leftovers from previous builds, if any
>>> def foo():
... try:
... print('start')
... yield 1
... yield 2
... print('bye')
... except GeneratorExit:
... print('forced exit')
...
>>> f = foo()

To keep compatibility with CPython, we need to generate a trampoline for each method which uses one of HPy calling conventions, e.g.:

HPy_DEF_METH_VARARGS(add_ints)
static HPy add_ints_impl(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t nargs);

After this, add_ints is a function of type HPyMeth (which is different in the CPython and the Universal cases), and can be put inside an

@antocuni
antocuni / hpy.h
Created May 19, 2020 12:42
HPy methods
#define METH_NOARGS 1
#define METH_O 2
typedef void* HPyContext;
typedef long HPy;
typedef HPy (*HPyMeth_NOARGS)(HPyContext, HPy);
typedef HPy (*HPyMeth_O)(HPyContext, HPy, HPy);
typedef struct {
import sys
def main():
myvar = 'hello'
print('this is line 5')
print('this is line 6')
print('this is line 7')
print('this is line 8')
print('this is line 9')