Skip to content

Latest commit

 

History

History
50 lines (39 loc) · 2.16 KB

File metadata and controls

50 lines (39 loc) · 2.16 KB

Fast-FizzBuzz-python

For https://codegolf.stackexchange.com/questions/215216/high-throughput-fizz-buzz/. Do check out the awesome submissions by others and the benchmark code is here if you want to run it on your machine https://github.com/omertuc/fizzgolf.

Usage on google colab

Change the output number (1e9 for < 2 min runtime) (1e8 for <20 s runtime)

fizzbuzz_numpy_os.py and fizzbuzz_pure_python.py

!apt-get install pv
!python3 fizzbuzz_numpy_os.py | pv > /dev/null
or
!python3 fizzbuzz_pure_python.py | pv > /dev/null

fizzbuzz_multiprocessing_numpy_os.py and fizzbuzz_multiprocessing_numpy_os_improvised_lock.py

#install python 3.9
!sudo apt-get update -y
!sudo apt-get install python3.9

#change alternatives
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2

#check python version
!python --version

#Pip !apt-get install python3-pip
!apt install python3.9-distutils
!python3 -m pip install --upgrade pip
!pip install numpy
!apt-get install pv
!python3 fizzbuzz_multiprocessing_numpy_os.py | pv > /dev/null

Performance on google collab, length = int(1e9)

!python3 fizzbuzz_numpy_os.py | pv > /dev/null #chunk 8100
7.33GiB 0:00:59 [ 125MiB/s] [ <=> ]

!python3 fizzbuzz_pure_python.py | pv > /dev/null #chunk 6000
7.33GiB 0:01:25 [87.5MiB/s] [ <=> ]

!python3 fizzbuzz_multiprocessing_numpy_os.py | pv > /dev/null #chunk 1500000
7.34GiB 0:01:27 [85.7MiB/s] [ <=> ]

!python3 fizzbuzz_multiprocessing_numpy_os_improvised_lock.py | pv > /dev/null #chunk 1500000
7.34GiB 0:01:14 [ 100MiB/s] [ <=> ]

Notes

fizzbuzz_multiprocessing_numpy_os.py is slow on colab because of the overhead from making new processes.
If there were more cores and with larger strings it might be possible to overcome this.