pyperformance icon indicating copy to clipboard operation
pyperformance copied to clipboard

A more pythonic Richards benchmark?

Open adsharma opened this issue 4 years ago • 3 comments

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:

  • dataclasses
  • enums
  • python3 type annotations
  • static transpilation via py2many

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 avatar May 25 '21 04:05 adsharma

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.

adsharma avatar May 27 '21 23:05 adsharma

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?

markshannon avatar Jun 16 '21 12:06 markshannon

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

  • Use of dataclasses
  • Generalized Algebraic data types, functional programming techniques. Usage is going up because of the mindshare rust has garnered in the last few years.
  • Aspect oriented programming using python decorators (The only ones I see are staticmethod/classmethod and one instance of @coroutine)
  • async/await

adsharma avatar Jun 16 '21 16:06 adsharma