glyph / FastFizzBuzz

an experiment in making FizzBuzz faster in Python
3 stars 0 forks source link

Scaffolding? #1

Open eirik-schwenke opened 2 years ago

eirik-schwenke commented 2 years ago

Hi,

really appreciated the blog post, and the code - but it might be nice if the README included commands to (re)-generate the results.csv-file, along with how to compile and run the c-code? (eg: make fizzbuzz - no Makefile needed - except one would want -O3 etc...).

Personally, as a relative newcomer to "production" python, I'd also love to see some more expansion on:

It’s worth noting that the technique I used to produce the extension modules to test was literally pip install mypy; mypyc .../module.py, then python -c “import module”.

Maybe something along the lines of (I'm sure there are better approaches):

Compile the C code

make fizzbuzz
mv fizzbuzz fizzbuzz.unopt
CFLAGS="-O3" make fizzbuzz
mv fizzbuzz fizzbuzz.o3

Quick test - pipe through pv for gauging speed:

./fizzbuzz.unopot | pv -a > /dev/null

[ 145MiB/s]

./fizzbuzz.o3 | pv -a > /dev/null

[ 152MiB/s]

Quick test - python

python src/fastfizzbuzz/python_template.py | pv -a > /dev/null 

[81,6MiB/s]

python src/fastfizzbuzz/python_naive.py | pv -a > /dev/null 

[9,45MiB/s]

Quick test - python - mypy

# with python 3.10.4:
pip install mypy
mypyc src/fastfizzbuzz/python_template.py
mypyc src/fastfizzbuzz/python_naive.py

python -c "from python_template import fizzbuzz;fizzbuzz()" | pv -a > /dev/null

[ 107MiB/s]

python -c "from python_naive import fizzbuzz;fizzbuzz()" | pv -a > /dev/null

[11.0MiB/s]

glyph commented 2 years ago

Sure, I'd love a PR :)