[Python-Dev] Silly little benchmark

Neil Schemenauer nas@python.ca
Fri, 13 Jul 2001 05:38:40 -0700

Jeremy Hylton wrote:
> The big change is the coercion work being done in binary_op1(), which
> tries to turn strings into numbers in a variety of ways.  BINARY_ADD
> calls PyNumber_Add(), which calls binary_op1().  When the binary_op1()
> calls fails, it then tries sequence concatenation.
> If it were possible for binary_op1() to fail quickly for non-numeric
> sequences like strings, we would not see the slowdown for small string
> operations.  (I believe that's what the silly little benchmark shows
> and what one of the pybench tests shows.)

I had a patch that did this:

    * Added an ordinal number to some builtin types.  All other types
      had ordinal 0.

    * Built a 2-D table of binary methods.

    * Had operations like PyNumber_Add look into this table and use the
      method there.

It turned out to not give much of a speedup but I think the idea is