Benchmarking by Dannii Willis

I took a whack at updating @Dannii 's Benchmarking for 6M62, mostly just by naively cutting out its roll-your-own real numbers and replacing them with I7-native ones. To my great surprise it… looks like it works? Here’s Benchmarking in my github fork of the Friends of I7 Extensions.

(Using green to highlight the fastest result isn’t working yet.)

BTW, really nicely formatted output here, Dannii.

2 Likes

Nice! Feel free to update the extension directly.

1 Like

I’ve pushed the revised version to the Friends of I7. I had thought I’d left the code in a mess, but it wasn’t that bad. The previous example no longer compiled, so I provided an example with different ways to test a container for emptiness with some surprising results.

First the unsurprising results:

  • an in-line if the first thing held by the box is nothing is the winner
  • if nothing is in the box is terrible

The runner up was:

Include (-
[ HoldsNothing obj;
  if (child(obj)) rfalse;
  rtrue;
];
-);

To decide whether (C - a container) is void-like:
    (- HoldsNothing({C}) -)

But even this takes twice as long: the function invocation overhead is significant. (Mind you, we’re talking about the difference between .28 microseconds and .56 microseconds on my machine… it’s not like the latter is a bad solution.)

Adjectives impose more overhead than a straight function call. The adjective versions of the above:

Definition: a container is empty rather than non-empty if the first thing held by it is nothing.

Definition: a container is devoid-of-content rather than non-devoid-of-content if I6 routine "HoldsNothing" says so (it has nothing in it).

are noticeably slower, at .91 microseconds and 1.36 microseconds respectively on my machine. A surprise is that the following placed in between them at 1.17 microseconds: if there is nothing in the box which evidently is represented entirely differently from if nothing is in the box (but I haven’t looked at what the I6 is.)

Twice as slow as that is unless there is something in the box (and I had to word it that way because if there is not something in the box compiles but produces backwards results for reasons I haven’t chased down).

And then if nothing is in the box is some 30 times slower than that, and if the number of entries in the list of things held by the box is zero some 7 times slower than that.

3 Likes

What about this, without the intermediate function call?

To decide whether (C - a container) is void-like:
    (- (~~child({C})) -)

My guess is that’s equivalent to if the first thing held by the box is nothing.

Or this, if we really want an adjective because it gives a nice syntax:

Definition: a container is empty if I6 condition "(~~child(*1))" says so (it has nothing in it).

This syntax—a kind of macro—is explained in the section “Inform 6 adjectives” of the “Extensions” chapter. I haven’t tested, but according to the documentation, it should be as fast as above, because it doesn’t call a routine like a regular definition does. I haven’t tested, though.

I haven’t been meticulous about a clean-room environment (read as: I’ve had my browser running too), so I’ll go with To decide whether (C - a container) is void-like: (- (~~child({C})) -) vs. first thing held by C is nothing is too close to call without being fussier. And likewise the Adjective version vs. the other’s Adjective version (which is to say taking some 4 times as long as the non-Adjective version).

I knew about if I6 routine... says so (and it was one of the variants I tried along the way) but I had missed if I6 condition – good to know. (I stopped midway through Ch. 27 to start reading the DM4…)