python / pyperformance

Python Performance Benchmark Suite
http://pyperformance.readthedocs.io/
MIT License
870 stars 175 forks source link

A more pythonic Richards benchmark? #101

Open adsharma opened 3 years ago

adsharma commented 3 years ago

The richard's benchmark included with pyperformance seems to be a C -> C++ -> Java -> Python port. It makes heavy use of object oriented programming and doesn't look anything like the original C code.

I've been playing with the python2 version distributed from their website. I ported it to python3. It looks more like the C version, which has some good things and a few bad things:

+ Covers non-OO programming use case - Overloads variables as in Union[int, Type1, Type2]

I'm in the process of improving it to Optional[Type1] and Optional[Type2]

My goal is to explore a dialect of statically typed python using modern pythonic constructs:

The code is here: https://github.com/adsharma/richards-benchmark. Let me know if this sounds interesting and if you'd like to update the variant in the repo at some point in the future. I hear some of the faster cpython work is using these benchmarks.

adsharma commented 3 years ago

Using the @sealed decorator derived from the adt library makes it around 4-5x slower than the Java derived version. Likely because of all the isinstance() checks inside the libary. Need to benchmark it again when python supports something similar natively.

My goal is to transpile this version of the library to rust and see how well the transpiled + optimized code performs.

markshannon commented 3 years ago

What is wrong with the richard's benchmark being OO? OO programming is widely used. Do you think that OO programming is over represented in the benchmark suite as a whole?

adsharma commented 3 years ago

Certainly OO programming is widely used and should be proportionately represented. I feel the following are underrepresented: