[Python-Dev] Silly little benchmark

Tim Peters tim@digicool.com
Wed, 11 Jul 2001 01:05:52 -0400

[Skip Montanaro]
> Real time doesn't mean much on an operating system that can
> juggle multiple tasks, no matter how quiescent you try to make it.

If this made any difference in the results I reported, they wouldn't have
been reproducible to nearly 3 significant digits.  That's why I printed the
times for 3 runs of each -- you can trust that I know what I'm doing here.
These things run for a fraction of a second each, the machine was as quiet
as possible, and the output showed no cause for suspicion (indeed, I threw
out a few runs where one of the three numbers was 10x larger than the other
two -- *that's* how you know you got socked by a background task, provided
you've got a sensitive timer to work with).

> ...
> It still appears there's a big slowdown between 1.6 and 2.1 in
> the back tic operations though.

This assumes too much.  ``1`+`2`` triggers three reprs and a string
concatenation.  I suspect both slowed, but that the latter is the more
important hit.

First the repr(string) hit (first blob from the release20 rev of

*** 374,383 ****
  			c = op->ob_sval[i];
  			if (c == quote || c == '\\')
  				*p++ = '\\', *p++ = c;
! 			else if (c < ' ' || c >= 0177) {
! 				sprintf(p, "\\%03o", c & 0377);
! 				while (*p != '\0')
! 					p++;
  				*p++ = c;
--- 442,456 ----
  			c = op->ob_sval[i];
  			if (c == quote || c == '\\')
  				*p++ = '\\', *p++ = c;
! 			else if (c == '\t')
! 				*p++ = '\\', *p++ = 't';
! 			else if (c == '\n')
! 				*p++ = '\\', *p++ = 'n';
! 			else if (c == '\r')
! 				*p++ = '\\', *p++ = 'r';
! 			else if (c < ' ' || c >= 0x7f) {
! 				sprintf(p, "\\x%02x", c & 0xff);
!                                 p += 4;
  				*p++ = c;

"The usual" string char endures twice as many tests+branches now.

The other thing Jeremy has noted before:  string+string is slower than it
used to be, because BINARY_ADD now tries oodles of "sophisticated" ways to
coerce the operands to numbers before considering it might be asking for a
sequence catenation instead.  Given that the benchmark pastes together two
1-character strings, this overhead is overwhelming compared to the
concatenation work.

> Aside: Tim, can I assume by your return address that Digital Creations
> finally gave you an office and you're not computing from some seedy
> motel room on US 1? ;-)

I'm not entirely sure DC gave it to us, but there is indeed a Luxurious
PythonLabs World Headquarters now, in Falls Church, VA.  Conveniently
located atop an inaccessible hill, it overlooks the fabulous Leesburg Pike,
a stunning continuous strip mall stretching from the Potomac to the Arctic
Circle (or France, whichever is closer -- geography isn't my strong suit).

join-us-for-lunch!-we-need-the-company-ly y'rs  - tim